110,536
社区成员
发帖
与我相关
我的任务
分享
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();
}
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
甚至是
System.Windows.Forms.Application.StartupPath
不要跟我说 .我这是服务不是exe..static void Main()
{
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Service where name='MyWindowsService'"))
using (var services = searcher.Get())
{
foreach (var s in services)
{
Console.WriteLine(s["DisplayName"] + ": " +s["PathName"]);
}
}
}