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服务的名称。但我也希望得到它的物理路径。有什么帮助吗?