.net 如何安装同一个windows服务的多个实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8725082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to install multiple instance of same windows service
提问by Pooja
I created one windows serives
我创建了一个 Windows 服务
It gets the name of the service from web config file.
它从 Web 配置文件中获取服务的名称。
I used the below link for getting value from webconfig. http://www.codeproject.com/KB/dotnet/MultipleInstNetWinService.aspx
我使用以下链接从 webconfig 获取价值。 http://www.codeproject.com/KB/dotnet/MultipleInstNetWinService.aspx
for installing my windows service,i just click the icon and install again, i change the value in config file and rebulid my application.
为了安装我的 Windows 服务,我只需单击图标并再次安装,我更改配置文件中的值并重新构建我的应用程序。
again i try to install, it shows error like the specified service already exist.
我再次尝试安装,它显示错误,如指定的服务已经存在。
How to install multiple instance of same windows service?
如何安装同一个windows服务的多个实例?
Thanks, Pooja
谢谢,普佳
采纳答案by shamp00
You need to copy your service executable to a separate directory and use InstallUtil.exe to give it a different service name.
您需要将服务可执行文件复制到单独的目录,并使用 InstallUtil.exe 为其指定不同的服务名称。
It sounds like you missed this section in the linked article
From a command prompt, you'll need to use InstallUtil to install both instances of your service. For instructions on how to use InstallUtil, see Installer Tool (InstallUtil.exe). Once you're done installing the service instances, you'll have something like the services console above where Service Instance 1and Service Instance 2are created from the same executable, only installed from different directory locations with a different service name.
在命令提示符下,您需要使用 InstallUtil 来安装服务的两个实例。有关如何使用 InstallUtil 的说明,请参阅安装程序工具 (InstallUtil.exe)。完成服务实例的安装后,您将拥有类似于上面的服务控制台的内容,其中服务实例 1和服务实例 2是从同一个可执行文件创建的,仅从具有不同服务名称的不同目录位置安装。
回答by Naeem Sarfraz
I needed to do this for a quick demo of a service running with different parameters.
我需要这样做以快速演示使用不同参数运行的服务。
I copied the directory containing the service exe and then used the sc createcommand to setup the second service.
我复制了包含服务 exe 的目录,然后使用该sc create命令设置第二个服务。
sc create "[NewServiceName]" binPath="[PathToCopiedServiceDirectory]"
回答by mongesh madhavan
sc create MyService binPath= "MyService.exe" DisplayName= "MyService"
sc description MyService "My description"
Reference: http://support.microsoft.com/kb/251192
参考:http: //support.microsoft.com/kb/251192
Followed marked answer and wasted an hour. it was simple using sc create command
遵循标记的答案并浪费了一个小时。使用 sc create 命令很简单
回答by Victor Arce
I had to change the service name in the file "ProjectInstaller.Designer.cs" in visual studio and recompile. Hope it helps.
我不得不在 Visual Studio 中更改文件“ProjectInstaller.Designer.cs”中的服务名称并重新编译。希望能帮助到你。
回答by CuriousMind
Run the asp.net command prompt as administrator and then use the command - installutil "c:\abc\xyz.exe".
以管理员身份运行 asp.net 命令提示符,然后使用命令 - installutil "c:\abc\xyz.exe"。
If your service is already install then you can uninstall first using the command - installutil \u "c:\abc\xyz.exe"
如果您的服务已经安装,那么您可以先使用命令卸载 - installutil \u "c:\abc\xyz.exe"

