解决方案1:
NET START HttpAnalyzer_StdV7_NetFilter START start HttpAnalyzerStdV7.exe
将以上内容保存为.bat
解决方案2:
public static void Stat() { //检查是否包含此服务 if (ISWindowsServiceInstalled("HttpAnalyzer_StdV7_NetFilter1")) { if (!ISStart("HttpAnalyzer_StdV7_NetFilter")) { StartService("HttpAnalyzer_StdV7_NetFilter"); } Process.Start("HttpAnalyzerStdV7.exe"); } else { System.Windows.Forms.MessageBox.Show("不存在服务,请安装服务。"); } } /// <summary> /// 判断是否安装了某个服务 /// </summary> /// <param name="serviceName"></param> /// <returns></returns> public static bool ISWindowsServiceInstalled(string serviceName) { try { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName == serviceName) { return true; } } return false; } catch { return false; } } /// <summary> /// 判断某个服务是否启动 /// </summary> /// <param name="serviceName"></param> public static bool ISStart(string serviceName) { bool result = true; try { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName == serviceName) { if ((service.Status == ServiceControllerStatus.Stopped) || (service.Status == ServiceControllerStatus.StopPending)) { result = false; } } } } catch { } return result; } /// <summary> /// 启动某个服务 /// </summary> /// <param name="serviceName"></param> public static void StartService(string serviceName) { try { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName == serviceName) { service.Start(); service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 30)); } } } catch { } }
以上两种方案必须放到HTTPAnalyzerFull安装目录才可以运行。
附上源码: