How to get service execuable path

Posted wzjhoutai

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to get service execuable path相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

How To Easily Call WCF Services Properly z

How to Remove A Service Entry From Win10 Service List

How to Prolong the Service Life of Cone Crusher

How To Install WildFly as a Service on Linux

How to CORS enable ArcGIS Server 10.2.1 to Access REST Services without Using proxy.ashx

How to get checksum by IAR