zoukankan      html  css  js  c++  java
  • 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;
    }


  • 相关阅读:
    10-3 集合之Set
    【Angular】排序
    【Mongous】
    【验证码】
    爬虫
    【DOM】
    年月日
    【Mocha】
    【Test】
    洛谷——P1823 音乐会的等待
  • 原文地址:https://www.cnblogs.com/wzjhoutai/p/6859943.html
Copyright © 2011-2022 走看看