操作Windows Service
Namespace: System.ServiceProcess
Assembly: system.serviceprocess.dll
//—-判断本机是否运行了某项服务
ServiceController service = new ServiceController("MSSQLSERVER");
if(service.Stauts == ServiceProcess.ServiceControllerStatus.Running){…}
//—改变Service运行状态
private const string myService = "XXX";
ServiceController service = new ServiceController(myService );
if(service.Status != ServiceControllerStatus.Stopped)
{
service.Stop();
serviceControl.WaitForStatus(ServiceControllerStatus.Stopped);
}
service.Start();
//—-安装.net service
%SystemRoot%\Microsoft.NET\Framework\<Version>\InstallUtil /u /name=S1 myService.exe
%SystemRoot%\Microsoft.NET\Framework\<Version>\InstallUtil /name=S1 myService.exe
%SystemRoot%\system32\services.msc /s
//—-命令行操作
net start "myService"
net stop "myService"
