wincc判断系统服务运行状态,重启服务的例子:
If (HMIRuntime.Tags("@PRF_CLDCN_TAG_FAILED_WRITES_TOTAL").Read > 0) Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name = 'CCCloudConnect'")
For Each objService In colServiceList
Msgbox(objService.State)
If objService.State = "Running" Then
objService.StopService()
Wscript.Sleep 5000
objService.StartService()
End If
'errReturnCode = objService.ChangeStartMode("Disabled")
Next
Msgbox("ok")
End If
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='CCCloudConnect'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='CCCloudConnect'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next