《1》创建WbemScripting.SwbemLocator对象。
《2》连接到root/cimv2命名空间。
《3》按条件查询 win32_operatingsystem 项,条件:primary值为真。
用户名和密码的判断直接加入错误事件处理:Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$computer = "192.168.1.239" ;计算机名
$Remoteuser = "administrator";计算机用户
$Remotepass = "Password";计算机密码
$objlocator= ObjCreate ("wbemscripting.swbemlocator")
$objWMIService=$objlocator.connectserver($computer,"root/cimv2",$Remoteuser,$Remotepass)
If @error Then
MsgBox(0,"","出错错误,可能无法验证用户名!")
Exit
EndIf
$colItems = $objWMIService.ExecQuery("SELECT * FROM win32_operatingsystem where primary= true")
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
;~ MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
;~ "err.description is: " & @TAB & $oMyError.description & @CRLF & _
;~ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
;~ "err.number is: " & @TAB & $HexNumber & @CRLF & _
;~ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
;~ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
;~ "err.source is: " & @TAB & $oMyError.source & @CRLF & _
;~ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
;~ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
;~ )
Return SetError(1,1,$HexNumber)
EndFunc ;==>MyErrFunc
|