使用自定义名称安装windows服务

使用自定义名称安装windows服务,windows,windows-services,Windows,Windows Services,我有一个带有windows服务的exe文件。要安装它,我使用以下命令: installutil myService.exe/ShowCallStack 然后,我可以看到“服务”窗口中列出的“服务1” 我的问题是,是否可以安装相同服务的两个实例(使用相同的exe),但名称不同。我想在不改变源代码的情况下做到这一点 谢谢您的服务是否有ProjectInstaller课程?如果将ProjectInstaller添加到服务中,则可以编辑ProjectInstaller的DisplayName属性。这会将

我有一个带有windows服务的exe文件。要安装它,我使用以下命令:

installutil myService.exe/ShowCallStack

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

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


谢谢

您的服务是否有
ProjectInstaller
课程?如果将
ProjectInstaller
添加到服务中,则可以编辑ProjectInstaller的
DisplayName
属性。这会将名称从“Service1”更改为您想要的名称。有关ProjectInstaller的演练可以在MSDN上找到。

我以前使用过类似于以下脚本的内容。编辑服务名称,将其另存为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" ,"")

在服务安装期间可以使用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

干杯