$TimeOut = 60
_ServiceCheck()
Func _ServiceCheck($flag = True)
If $flag Then _Message('正在检查"Secondary Logon"服务状态')
Local $Res[2]
Local $starttime = TimerInit()
Do
$Res = _WMI_GetServiceState(".", "Secondary Logon")
Sleep(10)
_WMI_SetServiceState(".", "Secondary Logon", $Res)
Sleep(10)
$Passtime = TimerDiff($starttime)
Until ($Res[1] == 'Running') Or ($Passtime > $TimeOut * 1000)
If $Res[1] == 'Running' Then
If $flag Then _Message('"Secondary Logon"服务正常')
Sleep(1000)
SplashOff()
Return SetError(0, 1, True)
ElseIf ($Passtime > $timeout * 1000) Then
_Message('"Secondary Logon"服务未正常启动,等待超时')
Sleep(1000)
SplashOff()
MsgBox(0, '失败', '关键服务"Secondary Logon"没有成功启动')
Return SetError(0, 1, False)
EndIf
EndFunc ;==>_ServiceCheck
Func _WMI_GetServiceState($ip, $Caption)
Local $Res[2], $colItems
Local $objWMIService = ObjGet("winmgmts:\" & $ip & "\root\CIMV2")
If @error Then
$Res[0] = '未知'
$Res[1] = '未知'
$objWMIService = ''
Return SetError(1, 0, $Res)
Else
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", 48)
For $objItem In $colItems
;~ If $objItem.Caption =$Caption Then Return $objItem.Started;表示服务是启动(true)还是停止(false)
If $objItem.Caption = $Caption Then
$Res[0] = $objItem.StartMode
$Res[1] = $objItem.State
EndIf
Next
$colItems = ''
$objWMIService = ''
Return SetError(0, 0, $Res)
EndIf
EndFunc ;==>_WMI_GetServiceState
Func _WMI_SetServiceState($ip, $Caption, $set)
Local $Res[2], $colItems
Local $objWMIService = ObjGet("winmgmts:\" & $ip & "\root\CIMV2")
If @error Then
$Res[0] = '未知'
$Res[1] = '未知'
$objWMIService = ''
Return SetError(1, 0, $Res)
Else
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", 48)
For $objItem In $colItems
;~ If $objItem.Caption =$Caption Then Return $objItem.Started;表示服务是启动(true)还是停止(false)
If $objItem.Caption = $Caption Then
$Res[0] = $objItem.ChangeStartMode('Automatic')
Switch $set[1]
Case 'Running'
Case 'Paused'
$Res[1] = $objItem.ResumeService()
Case 'Stopped'
$Res[1] = $objItem.StartService()
EndSwitch
EndIf
Next
$colItems = ''
$objWMIService = ''
Return SetError(0, 0, $Res)
EndIf
EndFunc ;==>_WMI_SetServiceState
Func _Message($message)
Local $w = 200, $h = 50
SplashTextOn("请稍候", $message, 400, 100, Default, Default, 16, 11)
ControlSetText("请稍候", "", "Static1", $message)
Sleep(2000)
EndFunc ;==>_Message
回复 6# netegg |