在同一台电脑上安装多个版本的 Windows 服务

发布于 2024-10-05 13:17:38 字数 160 浏览 2 评论 0原文

我有一个 .NET 3.5 Windows 服务,它有几种不同的配置/风格,即。发布、测试、调试等。我已经为该服务创建了一个安装程序包,它是作为 msbuild 脚本的一部分构建的,但我需要能够以允许每种服务风格的方式构建安装程序。安装在同一台机器上。有谁知道最好的方法来做到这一点?

谢谢

I have a .NET 3.5 Windows Service that comes in several different configurations/flavours ie. Release, Test, Debug etc. I've created an installer package for the service which is built as part of an msbuild script, but I need to be able to build the installers in a way which would allow each flavour of the service to be installed on the same machine. Does anyone know the best way to do this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身软味 2024-10-12 13:17:38

也许这篇文章会有帮助?

问题

查看ServiceInstaller
使用 Reflector 的类,你会看到它
CreateService 进行 Win32 调用
ServiceInstaller.Install 方法。
CreateService 将返回
ERROR_DUPLICATE_SERVICE_NAME 返回
每当调用该方法时都编写代码
带有 serviceNamedisplayName
匹配的参数
已经安装的服务。这是
是什么导致了 Win32Exception
扔进上面的窗口并
最终导致第二次安装
失败。您可以查看完整的
有关 CreateService 的文档
函数此处

要解决这个问题,需要做的就是
要做的就是动态设置
安装期间的服务名称和
服务启动到已知值并且
确保该值不同
对于您的服务的每个实例
安装。

解决方案

所需要做的就是使
确保每个服务的名称
安装实例是唯一的。然后
你需要有以下副本
每个的安装目录
您想要的服务实例。
最后,您需要能够设置
期间动态的服务名称
安装和启动。这将是
使用app.config文件来促进。

本文继续提供有关如何在同一台计算机上安装 .NET Windows 服务的多个实例的分步说明。

当然,我忍不住想知道为什么您需要在同一台计算机上同时运行调试和发布版本。

Perhaps this article will be of help?

The Problem

When reviewing the ServiceInstaller
class using Reflector, you'll see it
does a Win32 call to CreateService in
the ServiceInstaller.Install method.
CreateService will return the
ERROR_DUPLICATE_SERVICE_NAME return
code whenever the method is called
with a serviceName or displayName
parameter that matches that of an
already installed service. This is
what causes the Win32Exception to be
thrown in the above window and
ultimately causes the second install
to fail. You can view the complete
documentation on the CreateService
function here.

To get around this, all that needs to
be done is to dynamically set the
service name during installation and
service startup to a known value and
to make sure that value is different
for each instance of the service you
install.

The Solution

All that needs to be done is to make
sure that the name of each service
installation instance is unique. Then
you need to have copies of
installation directories for each
service instance you'd like to have.
Finally, you need to be able to set
the service name dynamically during
installation and startup. This will be
facilitated using the app.config file.

The article continues by providing step-by-step instructions on how you can install multiple instances of a .NET Windows Service on the same machine.

Of course, I can't help but wonder why exactly you would need to run a Debug and Release version at the same time on the same machine.

〗斷ホ乔殘χμё〖 2024-10-12 13:17:38

只是想提请注意 Cody Gray 参考文献中的评论。看来作者和评论者都同意使用 sc.exe 有一种更简单的方法,如下所示

sc \\myserver create NewService binpath= c:\nt\system32\NewServ.exe

Just wanted to draw attention to the comments in the article Cody gray references. It seems that the author and a commenter agreed that there was an easier method using sc.exe as follows

sc \\myserver create NewService binpath= c:\nt\system32\NewServ.exe
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文