743
社区成员
发帖
与我相关
我的任务
分享
'ServiceController对象作成成
Dim sc As New System.ServiceProcess.ServiceController("Telnet", ".")
If sc.Status = System.ServiceProcess.ServiceControllerStatus.Stopped Then
'如果服务停止时,开始
sc.Start()
Else If sc.CanStop Then
'服务停止
sc.Stop()
End If
'中断,再启动是否可能检测
If sc.CanPauseAndContinue Then
If sc.Status = System.ServiceProcess.ServiceControllerStatus.Paused Then
'中断时继续
sc.Continue()
Else
'服务中断
sc.Pause()
End If
End If
'至服务停止等待
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped)