确定服务是否已安装
作为安装 Windows 服务的一部分,我编写了 installutil 和命令行的替代方案:
IDictionary state = new Hashtable();
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MyServiceClass).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
//# Service Account Information
inst.Install(state);
inst.Commit(state);
}
安装它。我通过检测是否启动成功来确定是否需要执行此操作。我预计请求启动和实际设置 RunningOk 标志之间会有延迟,并且宁愿采用通用的编程解决方案。 ( 如何以编程方式安装 Windows 服务C#? ) http://dl.dropbox.com/u/152585/ServiceInstaller.cs 解决方案已经有近 3 年历史了,很长,并且导入了 DLL,从我对 .NET 的了解来看,这似乎破坏了它的安全性意图。
因此,我想知道一种更简洁的方法来使用 .NET 执行此操作(如果存在)?
As part of installing my windows service I have coded an alternative to installutil and the command line:
IDictionary state = new Hashtable();
using (AssemblyInstaller inst = new AssemblyInstaller(typeof(MyServiceClass).Assembly, args))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
//# Service Account Information
inst.Install(state);
inst.Commit(state);
}
to intall it. I determing whether this needs doing by detecting whether it starts successfully. I anticipate delay between requesting it start and it actually setting it's RunningOk flag and would rather a generic, programmatic solution. The ( How to install a windows service programmatically in C#? ) http://dl.dropbox.com/u/152585/ServiceInstaller.cs solution is nearly 3 years old, long, and imports DLL's which from the little I know about .NET seems to defeat its security intentions.
Hence I would like to know of a more concise way to do this with .NET, if one exists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要查找服务以及它是否正在运行,
请注意,它实际上检查它是否未停止,而不是它是否正在运行,但如果您愿意,您可以更改它。
很高兴在简洁的 .NET 结构中做到这一点。不记得我从哪里得到这些信息,但现在看起来很简单,值得发帖。
To find a service, and whether it is running,
Note it actually checks whether it is not stopped instead of whether it is running, but you can change that if you wish.
Nice to do this in concise .NET constructs. Don't recall where I got the info from but it looks so easy now and worth a post.
我建议使用Windows Installer 本机支持< /a>.
您可以管理服务安装、卸载以及启动或停止操作。
不幸的是,并非所有设置创作工具都提供对此的直接支持,因此您需要找到一个能够提供直接支持的工具。
I recommend using the Windows Installer native support.
You can manage the service install, uninstall and start or stop operations.
Unfortunately not all setup authoring tools offer direct support for this, so you will need to find one that does.