我有一个带有Windows服务的exe文件。为了安装它,我使用以下命令:
installutil myService.exe /ShowCallStack
然后,我可以在服务窗口中看到“service1”已列出。
我的问题是是否可能安装两个相同服务的实例(使用相同的exe),但具有不同的名称。我想在不更改源代码的情况下完成此操作。
谢谢
我有一个带有Windows服务的exe文件。为了安装它,我使用以下命令:
installutil myService.exe /ShowCallStack
然后,我可以在服务窗口中看到“service1”已列出。
我的问题是是否可能安装两个相同服务的实例(使用相同的exe),但具有不同的名称。我想在不更改源代码的情况下完成此操作。
谢谢
ProjectInstaller
的类?如果你向服务中添加了一个ProjectInstaller
,那么你就可以编辑ProjectInstaller
的ServiceInstaller属性中的DisplayName
。这将把名称从“Service1”更改为你想要的任何名称。有关ProjectInstallers的详细步骤,请参见MSDN上的这里。在 IT 相关领域,可以在服务安装期间使用 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。
谢谢。
我过去使用过类似下面脚本的东西。编辑服务名称,将其保存为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" ,"")