Path to the executable of a windows service

拜拜、爱过 提交于 2019-12-02 23:44:44
Hans Olsson

There's always the WMI class Win32_Service as described here, specifically the PathName.

This works:

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('"');
    }
}

You can obtain them from here using the Registry in HKLM:

 System\CurrentControlSet\Services\Service

Look for the ImagePath value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!