C# 从注册表获取Windows服务的文件路径
C# 从注册表获取Windows服务的文件路径
扫一扫加作者微信
获取Windows服务的文件名,从注册表获取Windows服务的文件路径。
C# Code:
/// <summary>
/// 获取Windows服务的文件名
/// </summary>
/// <param name="serviceName">Windows服务名</param>
/// <returns></returns>
public static string GetServiceFile(string serviceName)
{
RegistryKey _Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\services\" serviceName);
if (_Key != null)
{
object _ObjPath = _Key.GetValue("ImagePath");
if (_ObjPath != null)
{
return _ObjPath.ToString().Replace("\"", "");//去掉文件名两头的双引号
}
}
return "";
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
/// <summary>
/// 获取Windows服务的文件名
/// </summary>
/// <param name="serviceName">Windows服务名</param>
/// <returns></returns>
public static string GetServiceFile(string serviceName)
{
RegistryKey _Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\services\" serviceName);
if (_Key != null)
{
object _ObjPath = _Key.GetValue("ImagePath");
if (_ObjPath != null)
{
return _ObjPath.ToString().Replace("\"", "");//去掉文件名两头的双引号
}
}
return "";
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网