I have a windows service executable that I know is written in .NET which I need to install under a different service name to avoid a conflict. The install doesn't provide anyway to specify a service name. If I only have access to the binary, is there anyway to override the service name when I install it with installutil?
5 Answers
Do you have to use InstallUtil? Here are the commands to do what you want using sc:
sc create MyService binPath= "MyService.exe" DisplayName= "MyService"
sc description MyService "My description"
Reference: http://support.microsoft.com/kb/251192
-
1This looks like exactly what I want -- however I can't get it to work. I just keep getting a "usage" message.– NathanNov 10, 2009 at 15:42
-
35My problem was that there apparently must be a space between the equal sign and the binPath value, e.g. sc create ahSchedulerService binPath= "MyService.exe", not sc create ahSchedulerService binPath="MyService.exe".– NathanNov 10, 2009 at 15:56
-
-
When I used the SC command to create a service instance, I found that I had to put the entire path before the EXE name. Before running SC, I had changed my command prompt directory to be the same as the EXE, thinking that would be enough, but it wasn’t. When I tried to start the service, I got an error saying “system cannot find the file specified”. So the SC command has to have a parameter like: binPath= "C:\whatever\servieName.exe" Sep 8, 2019 at 15:35
It is not true that InstallUtil doesn't allow you to configure the service name. I do it all the time like this
InstallUtil.exe /servicename="<service name>" "<path to service exe>"
-
6if you already have a service with same name as exe, it will give error
System.ComponentModel.Win32Exception: The specified service already exists
. I was trying to install 2 instances of same service and naming them differently. Use sc create methods given in below answers– PUGDec 15, 2014 at 22:50 -
4
-
2Works if you have a project installer and override the install and uninstall like in @Volodymyrs answer stackoverflow.com/a/25259719/169714 Jul 5, 2016 at 10:22
-
-
- Add project installer to your service
Add method to get CustomService name
private void RetrieveServiceName() { var serviceName = Context.Parameters["servicename"]; if (!string.IsNullOrEmpty(serviceName)) { this.SomeService.ServiceName = serviceName; this.SomeService.DisplayName = serviceName; } }
call on install and uninstall
public override void Install(System.Collections.IDictionary stateSaver) { RetrieveServiceName(); base.Install(stateSaver); } public override void Uninstall(System.Collections.IDictionary savedState) { RetrieveServiceName(); base.Uninstall(savedState); }
installutil /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe
-
This was very useful, I did have to recompile my service executable to get it work once I added this code, that wasn't an issue for me. Jul 8, 2016 at 11:20
-
taken from the source link but incase... You need to change the “someService” to the ServiceInstaller name. It’s probably ServiceInstaller1 as that is the default.– J3RMFeb 2, 2021 at 17:05
This exactly worked for me!
I hope someone can use this.
Try installing your service with sc.exe. A quick search will yield lots documentation. With that tool it's easy to modify existing services and/or add new ones -- including names.
Edit: I install my .NET services with this tool.