/// <summary> /// 打开应用程序 /// </summary> /// <param name="appPath"></param> public static void AppStart(string appPath) { try { string appStartPath = appPath; IntPtr userTokenHandle = IntPtr.Zero; ApiDefinitions.WTSQueryUserToken(ApiDefinitions.WTSGetActiveConsoleSessionId(), ref userTokenHandle); ApiDefinitions.PROCESS_INFORMATION procInfo = new ApiDefinitions.PROCESS_INFORMATION(); ApiDefinitions.STARTUPINFO startInfo = new ApiDefinitions.STARTUPINFO(); startInfo.cb = (uint)Marshal.SizeOf(startInfo); ApiDefinitions.CreateProcessAsUser( userTokenHandle, appStartPath, "", IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref startInfo, out procInfo); if (userTokenHandle != IntPtr.Zero) ApiDefinitions.CloseHandle(userTokenHandle); int _currentAquariusProcessId = (int)procInfo.dwProcessId; } catch (Exception ex) { LogHelpr.Error("打开程序时出错:" + ex.ToString()); } }
/// <summary> /// 启动服务 /// </summary> /// <param name="serviceName">要启动的服务名称</param> private void StartService(string serviceName) { try { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName.Trim() == serviceName.Trim()) { service.Start(); //直到服务启动 service.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 30)); LogHelpr.Info(string.Format("启动服务:{0}", serviceName)); } } } catch (Exception ex) { LogHelpr.Error(ex.ToString()); } }
private bool CheckSericeStart(string serviceName) { bool result = true; try { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { if (service.ServiceName.Trim() == serviceName.Trim()) { if ((service.Status == ServiceControllerStatus.Stopped) || (service.Status == ServiceControllerStatus.StopPending)) { result = false; } } } } catch (Exception ex) { LogHelpr.Error(ex.ToString()); } return result; }