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?
Asked
Active
Viewed 6.5k times
5 Answers
117
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

Edward Brey
- 40,302
- 20
- 199
- 253

Josh Yeager
- 3,763
- 1
- 25
- 29
-
1This looks like exactly what I want -- however I can't get it to work. I just keep getting a "usage" message. – Nathan Nov 10 '09 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". – Nathan Nov 10 '09 at 15:56
-
Ah, I forgot about that. Sorry for giving you a bad example. – Josh Yeager Nov 11 '09 at 19:47
-
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" – John Gilmer Sep 08 '19 at 15:35
-
When running from `PowerShell` window, make sure to use `sc.exe` instead of `sc`, otherwise `PowerShell` thinks you mean `Set-Content`. – Aage Oct 19 '22 at 09:46
30
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>"

Sachin Kainth
- 45,256
- 81
- 201
- 304
-
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 – PUG Dec 15 '14 at 22:50
-
4
-
3Works if you have a project installer and override the install and uninstall like in @Volodymyrs answer http://stackoverflow.com/a/25259719/169714 – JP Hellemons Jul 05 '16 at 10:22
-
-
-
Received this Error: An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The specified service already exists Any way around? – Ayush Singhania May 03 '19 at 10:45
26
- 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

Crab Bucket
- 6,219
- 8
- 38
- 73

Vova Bilyachat
- 18,765
- 4
- 55
- 80
-
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. – Terry Kernan Jul 08 '16 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. – J3RM Feb 02 '21 at 17:05
7
This exactly worked for me!
I hope someone can use this.

kulNinja
- 526
- 6
- 14
-
-
dedicated to copy paste: `sc create FooService_v666 binPath= "c:\path\foo\bar.exe" DisplayName= "foo bar service" start= auto` – Max May 20 '23 at 19:33
2
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.

jsw
- 1,752
- 1
- 14
- 20