Home Windows Service File Name
Post
Cancel

Windows Service File Name

When you get a ServiceController instance, how do you know the executable name and path? WMI makes it possible. You can use this GetServicePath function to query service executable name and path.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private static string GetServicePath(ServiceController service)
{
    //construct the management path
    string path = "Win32_Service.Name='" + service.ServiceName + "'";
    ManagementPath p = new ManagementPath(path);
    //construct the management object
    ManagementObject ManagementObj = new ManagementObject(p);
    if (ManagementObj["pathName"] != null)
    {
        return ManagementObj["pathName"].ToString().Replace("\"", null);
    }
    else
    {
        return null;
    }
}
This post is licensed under CC BY 4.0 by the author.
Advertisement

GrapeVine Voice: DXCore for Visual Studio

GrapeVine Voice: Delay Because of Bandwidth

Comments powered by Disqus.