Reputation: 3807
I have an exe file with a windows service. To install it, i use the command:
installutil myService.exe /ShowCallStack
Then, i can see the "service1" listed in Services window.
My question is if it is possible to install 2 instances of same service (using the same exe) but with diferent names. I want to do that without changing the source code.
Thanks
Upvotes: 6
Views: 5108
Reputation: 2639
it is possible to use InstallUtil.exe.config during service installation, so my dirty hack was looking like:
In ProjectInstaller.designer.cs
this.Service1.Description = ConfigurationManager.AppSettings["ServiceDescription"] != null ? ConfigurationManager.AppSettings["ServiceDescription"] : "bla, bla, bla";
this.Service1.DisplayName = ConfigurationManager.AppSettings["DisplayName"] != null ? ConfigurationManager.AppSettings["DisplayName"] : "Service One";
this.Service1.ServiceName = ConfigurationManager.AppSettings["ServiceName"] != null ? ConfigurationManager.AppSettings["ServiceName"] : "Service1";
in InstallUtil.exe.config:
<configuration><appSettings><add key="ServiceName" value="Service1" /><add key="DisplayName" value="Service One" /><add key="ServiceDescription" value="bla, bla, bla" /></appSettings></configuration>
can't get how to post xml here
cheers
Upvotes: 1
Reputation: 8996
I've used something like the below script in the past. Edit the service names, save it as a VBS, and run it.
Const ExistingServiceName = "Service1"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objExistingService = objWMIService.Get("Win32_Service.Name='" & ExistingServiceName & "'")
Set objService = objWMIService.Get("Win32_BaseService")
Const NewServiceName = "Service2"
errReturn = objService.Create (NewServiceName, NewServiceName, objExistingService.PathName, OWN_PROCESS ,NOTIFY_USER ,"Manual" , NOT_INTERACTIVE ,".\LocalSystem" ,"")
Upvotes: 0
Reputation: 16719
Does your service have a ProjectInstaller
class? If you add a ProjectInstaller
to your service, then you can edit the DisplayName
property of the ProjectInstaller's ServiceInstaller. This will change the name from "Service1" to whatever you want it to be. A walkthrough on ProjectInstallers can be found on MSDN here.
Upvotes: 2