找回密码
 加入
搜索
查看: 2031|回复: 2

===哪位大大帮小弟看下3行代码,在线等。。===

[复制链接]
发表于 2009-10-19 15:32:41 | 显示全部楼层 |阅读模式
悬赏50金钱已解决
本帖最后由 871224 于 2009-10-19 15:35 编辑

这个是一段远程关机的代码:

$computer = "IP"  ;计算机名
$Remoteuser = "Name"计算机用户
$Remotepass = "Password";计算机密码

《1》$objlocator= ObjCreate ("wbemscripting.swbemlocator")
《2》$objWMIService=$objlocator.connectserver($computer,"root/cimv2",$Remoteuser,$Remotepass)
《3》$colItems = $objWMIService.ExecQuery("SELECT * FROM  win32_operatingsystem where primary= true")

问题1:《1》《2》《3》分别是什么意思?
问题2:如果《2》之前,先判断所提供的IP、Name、Password是否正确,怎么写呢?

最佳答案

查看完整内容

《1》创建WbemScripting.SwbemLocator对象。 《2》连接到root/cimv2命名空间。 《3》按条件查询 win32_operatingsystem 项,条件:primary值为真。 用户名和密码的判断直接加入错误事件处理:
发表于 2009-10-19 15:32:42 | 显示全部楼层
《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
 楼主| 发表于 2009-10-19 15:37:39 | 显示全部楼层
哪位能告诉我下啊,小弟不胜感激!!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-14 00:34 , Processed in 0.074780 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表