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
5 Comments
Nathan
This looks like exactly what I want -- however I can't get it to work. I just keep getting a "usage" message.
Nathan
My 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".
Josh Yeager
Ah, I forgot about that. Sorry for giving you a bad example.
John Gilmer
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"
Aage
When running from
PowerShell window, make sure to use sc.exe instead of sc, otherwise PowerShell thinks you mean Set-Content.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>"
6 Comments
PUG
if 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 answersJason Kelley
Does not work. Gives an error that my service already exists.
JP Hellemons
Works if you have a project installer and override the install and uninstall like in @Volodymyrs answer stackoverflow.com/a/25259719/169714
Gelootn
does not work on a default installer created from Visual studio
dbd
If I change parameter "servicename" to "name" it works for me.
|
- 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
2 Comments
Terry Kernan
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.
J3RM
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.

This exactly worked for me!
I hope someone can use this.
2 Comments
J.SMTBCJ15
image is broken
Max
dedicated to copy paste:
sc create FooService_v666 binPath= "c:\path\foo\bar.exe" DisplayName= "foo bar service" start= auto