gpt4 book ai didi

c# - 从 services.msc c# 获取服务路径

转载 作者:行者123 更新时间:2023-11-30 14:33:33 24 4
gpt4 key购买 nike

我正在尝试从 services.msc 获取服务可执行文件路径

我写了下一段代码:

  var service = ServiceController.GetServices().Where(p => p.ServiceName.Equals("Service name", StringComparison.InvariantCultureIgnoreCase));
if (service.Any())
//get service data

我找不到服务可执行路径的位置(如果有的话)?

在 services.msc 中我可以看到路径,所以我假设也可以通过代码获取它。 Example of service info in services.msc (see that executable path exists there)

有什么想法吗?

最佳答案

您可以像这样从注册表中获取它:

private static string GetServiceInstallPath(string serviceName)
{
RegistryKey regkey;
regkey = Registry.LocalMachine.OpenSubKey(string.Format(@"SYSTEM\CurrentControlSet\services\{0}", serviceName));

if (regkey.GetValue("ImagePath") == null)
return "Not Found";
else
return regkey.GetValue("ImagePath").ToString();
}

关于c# - 从 services.msc c# 获取服务路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16078027/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com