如何从另一个程序获取特定 Windows 服务的可执行文件的路径? 不幸的是,类 ServiceController (System.ServiceProcess) 没有为此提供方法或属性!
最佳答案
始终存在 WMI 类 Win32_Service
,如 here 所述,特别是 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('"');
}
}
关于c# - Windows 服务的可执行文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3071215/