.Net Windows 服务:从引用的程序集安装
有很多如何在一行中安装 Windows 服务的示例:
ManagedInstallClass.InstallHelper(
new[] { Assembly.GetExecutingAssembly().Location });
在 exe 模块中声明服务类之前,这可以正常工作。 但如果服务类位于引用的程序集中(未在可执行文件中声明,而是在链接的 dll 中声明),则相同的代码对我不起作用。
在这种情况下,服务也会注册,但无法启动,因为它是使用 dll 路径注册并指向 dll(当我尝试启动该服务时,事件日志中会出现“服务不是 win32 可执行文件”消息)
如果我更改GetExecutingAssembly().Location
到可执行路径,则找不到安装程序,并且根本不会注册服务。
是否可以将服务类放入引用的程序集中,并且仍然能够以最小的努力注册服务?
先感谢您!
There are lots of examples how to install windows service in one line:
ManagedInstallClass.InstallHelper(
new[] { Assembly.GetExecutingAssembly().Location });
That works fine until service class is declared in exe module.
But the same code doesn't work for me if service class is in referrenced assembly (not declared in executable, but in linked dll).
In such a case service is registered as well but can't be started as it is registered with dll path and points to dll ("service is not a win32 executable" message appears in event log when I try to start that)
If I change GetExecutingAssembly().Location
to executable path, then no installers are found and service is not registered at all.
Is it possible to put service class into referenced assembly and still have ability to register service with minimum effort?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一些 C# 代码,允许您“手动”安装/卸载服务(无需声明自定义 RunInstaller 属性):
here is some C# code that allows you to install/uninstall a service" manually" (without the need to declare custom RunInstaller attributes):