views:

57

answers:

3

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 !

A: 

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

 System\CurrentControlSet\Services\Service

Look for the ImagePath value.

Brian R. Bondy
A: 

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

Something like this might work:

ManagementClass mc = new ManagementClass("Win32_Service");
foreach(ManagementObject mo in mc.GetInstances())
{
    if(mo.GetPropertyValue("Name").ToString() = "NameYouWant")
    {
        return mo.GetPropertyValue("PathName").ToString();
    }
}
ho1