2010-12-23 36 views
6

我有一个带有windows服务的exe文件。要安装它,我用命令:安装带自定义名称的windows服务

installutil myService.exe/ShowCallStack

然后,我可以看到“服务1”,在服务窗口中列出。

我的问题是如果可以安装2个相同服务(使用相同的exe)的实例,但具有不同的名称。我想在不改变源代码的情况下做到这一点。

感谢

回答

0

我在过去使用过类似下面的脚本。编辑服务名称,将其保存为VBS并运行它。

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

请问您的服务有ProjectInstaller类?如果您将ProjectInstaller添加到您的服务中,则可以编辑ProjectInstaller的ServiceInstallerDisplayName属性。这会将名称从“Service1”更改为您希望的名称。 ProjectInstallers上的演练可以在MSDN here上找到。

0

可以服务在安装过程中使用InstallUtil.exe.config,所以我的肮脏的黑客一直在寻找这样的:

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

不能得到如何张贴在这里

XML

欢呼声