开发者

Install windows service with custom name

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" li开发者_JS百科sted 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


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.


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


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" ,"")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜