准备用AutoIt做一个系统服务运行状态监控软件,查看了一下WMI,发现WMI真的很强大!
通过下面的代码改编一下就可以实现想要的效果了!
; 生成于 AutoIt Scriptomatic
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$Output = $Output & "Computer: " & $strComputer & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("Select * FROM Win32_Service", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
For $objItem In $colItems
$Output = $Output & "AcceptPause: " & $objItem.AcceptPause & @CRLF
$Output = $Output & "AcceptStop: " & $objItem.AcceptStop & @CRLF
$Output = $Output & "Caption: " & $objItem.Caption & @CRLF
$Output = $Output & "CheckPoint: " & $objItem.CheckPoint & @CRLF
$Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF
$Output = $Output & "Description: " & $objItem.Description & @CRLF
$Output = $Output & "DesktopInteract: " & $objItem.DesktopInteract & @CRLF
$Output = $Output & "DisplayName: " & $objItem.DisplayName & @CRLF
$Output = $Output & "ErrorControl: " & $objItem.ErrorControl & @CRLF
$Output = $Output & "ExitCode: " & $objItem.ExitCode & @CRLF
$Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
$Output = $Output & "Name: " & $objItem.Name & @CRLF
$Output = $Output & "PathName: " & $objItem.PathName & @CRLF
$Output = $Output & "ProcessId: " & $objItem.ProcessId & @CRLF
$Output = $Output & "ServiceSpecificExitCode: " & $objItem.ServiceSpecificExitCode & @CRLF
$Output = $Output & "ServiceType: " & $objItem.ServiceType & @CRLF
$Output = $Output & "Started: " & $objItem.Started & @CRLF
$Output = $Output & "StartMode: " & $objItem.StartMode & @CRLF
$Output = $Output & "StartName: " & $objItem.StartName & @CRLF
$Output = $Output & "State: " & $objItem.State & @CRLF
$Output = $Output & "Status: " & $objItem.Status & @CRLF
$Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
$Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF
$Output = $Output & "TagId: " & $objItem.TagId & @CRLF
$Output = $Output & "WaitHint: " & $objItem.WaitHint & @CRLF
if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
$Output=""
Next
Else
Msgbox(0,"WMI 输出","No WMI Objects Found for class: " & "Win32_Service" )
Endif
Func WMIDateStringToDate($dtmDate)
Return (StringMid($dtmDate, 5, 2) & "/" & _
StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
& " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc