我在安装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标志之间会有延迟,并且更喜欢通用的编程解决方案。此(如何以编程方式在C#中安装Windows服务?)http://dl.dropbox.com/u/152585/ServiceInstaller.cs 解决方案已经存在将近3年时间,并且很长,而且从我所知道的.NET方面来看,导入DLL似乎破坏了它的安全意图 。
因此,如果存在.NET的更简洁方法,则希望了解该方法是什么?
ServiceController.GetServices().Any(s => s.ServiceName == serviceName);
:) - tsemerusing( ServiceController[] sc= ServiceController.GetServices( ) ) { .. }
- Astrogator