Any way to override .NET Windows Service Name without recompiling?

.NetWindows Services

.Net Problem Overview


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?

.Net Solutions


Solution 1 - .Net

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

Solution 2 - .Net

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>"

Solution 3 - .Net

  1. Add project installer to your service

  2. 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;
         }
     }
    
  3. 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);
     }
    
  4. installutil /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe

Source

Solution 4 - .Net

enter image description here

This exactly worked for me!

I hope someone can use this.

Solution 5 - .Net

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNathanView Question on Stackoverflow
Solution 1 - .NetJosh YeagerView Answer on Stackoverflow
Solution 2 - .NetSachin KainthView Answer on Stackoverflow
Solution 3 - .NetVova BilyachatView Answer on Stackoverflow
Solution 4 - .NetkulNinjaView Answer on Stackoverflow
Solution 5 - .NetjswView Answer on Stackoverflow