如何获取Windows服务exe的物理路径

时间:2018-05-28 10:53:07

标签: c# windows service

     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);
        }
    }

上面的代码列出了已安装的Windows服务的名称。但我也希望得到它的物理路径。有什么帮助吗?

0 个答案:

没有答案