Windows服务可执行文件的路径 [英] Path to the executable of a windows service
本文介绍了Windows服务可执行文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从另一个程序获取特定Windows服务可执行文件的路径?不幸的是,类ServiceController(System.ServiceProcess)没有为此提供方法或属性!
How can I get the path to the executable of a specific windows service from another program ? Unfortunately the class ServiceController (System.ServiceProcess) doesn't provide a method or property for that !
推荐答案
There's always the WMI class Win32_Service
as described here, specifically the PathName
.
这有效:
ManagementClass mc = new ManagementClass("Win32_Service");
foreach(ManagementObject mo in mc.GetInstances())
{
if(mo.GetPropertyValue("Name").ToString() == "<Short name of your service>")
{
return mo.GetPropertyValue("PathName").ToString().Trim('"');
}
}
这篇关于Windows服务可执行文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文