用AU3启动服务,如何等待服务完全启动好再执行下一步操作?
请教,用AU3启动或停止服务,如何等待服务完全启动好或完全停止好再执行下一步操作?谢谢! while _Service_QueryStatus 回复 2# netegg这是什么函数,写上去没有反应哦。 #Include <Services.au3>
while _Service_QueryStatus($sServiceName) = 1(已停止)/ 4(运行中) 回复 4# netegg
我试了不可以,你确定可以吗?蛋蛋。 本帖最后由 netegg 于 2015-2-25 21:30 编辑
while _Service_QueryStatus($sServiceName) =4(运行中)
_Service_Stop( $sServiceNa)
sleep(100)
wend
。。。。。 $TimeOut = 60
_ServiceCheck()
Func _ServiceCheck($flag = True)
If $flag Then _Message('正在检查"Secondary Logon"服务状态')
Local $Res
Local $starttime = TimerInit()
Do
$Res = _WMI_GetServiceState(".", "Secondary Logon")
Sleep(10)
_WMI_SetServiceState(".", "Secondary Logon", $Res)
Sleep(10)
$Passtime = TimerDiff($starttime)
Until ($Res == 'Running') Or ($Passtime > $TimeOut * 1000)
If $Res == '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, $colItems
Local $objWMIService = ObjGet("winmgmts:\\" & $ip & "\root\CIMV2")
If @error Then
$Res = '未知'
$Res = '未知'
$objWMIService = ''
Return SetError(1, 0, $Res)
Else
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", 48)
For $objItem In $colItems
;~ If $objItem.Caption =$CaptionThen Return $objItem.Started;表示服务是启动(true)还是停止(false)
If $objItem.Caption = $Caption Then
$Res = $objItem.StartMode
$Res = $objItem.State
EndIf
Next
$colItems = ''
$objWMIService = ''
Return SetError(0, 0, $Res)
EndIf
EndFunc ;==>_WMI_GetServiceState
Func _WMI_SetServiceState($ip, $Caption, $set)
Local $Res, $colItems
Local $objWMIService = ObjGet("winmgmts:\\" & $ip & "\root\CIMV2")
If @error Then
$Res = '未知'
$Res = '未知'
$objWMIService = ''
Return SetError(1, 0, $Res)
Else
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Service", "WQL", 48)
For $objItem In $colItems
;~ If $objItem.Caption =$CaptionThen Return $objItem.Started;表示服务是启动(true)还是停止(false)
If $objItem.Caption = $Caption Then
$Res = $objItem.ChangeStartMode('Automatic')
Switch $set
Case 'Running'
Case 'Paused'
$Res = $objItem.ResumeService()
Case 'Stopped'
$Res = $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 If _ServGetState($s_Serv) <> "Running" Then _ServStart($s_Serv) 不好意思,wmi我不会
页:
[1]