public static string GetWindowsServiceInstallPath(string ServiceName)
{ string key = @"SYSTEM\CurrentControlSet\Services\" + ServiceName; string path = Registry.LocalMachine.OpenSubKey(key).GetValue("ImagePath").ToString(); //替换掉双引号 path = path.Replace("\"", string.Empty); FileInfo fi = new FileInfo(path); return fi.Directory.ToString(); }