首页 > 其他 > 详细

How to get service execuable path

时间:2017-05-16 10:43:05      阅读:283      评论:0      收藏:0      [点我收藏+]

Some time we need to get specific service path and then do something you want. there are 2 way to get specific service path bellow.

private static string GetRegistData(string name)
{
	string registData;
	RegistryKey hkml = Registry.LocalMachine;
	RegistryKey system = hkml.OpenSubKey("SYSTEM", true);
	RegistryKey currentControlSet = system.OpenSubKey("CurrentControlSet", true);
	RegistryKey services = currentControlSet.OpenSubKey("services", true);
	RegistryKey key = services.OpenSubKey(name, true);
	registData = key.GetValue("ImagePath").ToString();
	return registData;
}

private static string GetServicePath(string name)
{
	ManagementClass mc = new ManagementClass("Win32_Service");
	foreach (ManagementObject mo in mc.GetInstances())
	{
		if (mo.GetPropertyValue("Name").ToString() == name)
		{
			return mo.GetPropertyValue("PathName").ToString().Trim(‘"‘);
		}
	}
	return string.Empty;
}


How to get service execuable path

原文:http://www.cnblogs.com/wzjhoutai/p/6859943.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!