0
     public static void GetServices() {
        var serviceList = new List<string>();
        var servicePathList = new List<string>();
        ServiceController[] services = ServiceController.GetServices();

        foreach (var service in services)
        {
            serviceList.Add(service.DisplayName);
        }

        serviceList.Sort();

        int serviceCount = 0;
        foreach (var service in serviceList)
        {
            serviceCount++;
            Console.WriteLine(serviceCount.ToString() + " - " + service);
        }
    }

Above code lists the names of the windows services installed. But I also want to get the Physical path of it. Any help?

Dharmindar
  • 377
  • 1
  • 4
  • 11
  • please refer this link https://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx – Mohan Srinivas May 28 '18 at 10:59
  • You'll have to P/Invoke the [QueryServiceConfig](https://msdn.microsoft.com/de-de/library/windows/desktop/ms684932(v=vs.85).aspx) function. The [QUERY_SERVICE_CONFIG](https://msdn.microsoft.com/de-de/library/windows/desktop/ms684950(v=vs.85).aspx) structure has the `lpBinaryPathName` member, which contains the command line. – Christian.K May 28 '18 at 10:59
  • Possible duplicate of [How to find windows service exe path](https://stackoverflow.com/questions/2833959/how-to-find-windows-service-exe-path) – Fabjan May 28 '18 at 11:00

0 Answers0