[提问]代码在VBS中正常,在AU3中不正常,是哪里问题呢?
先看VBS代码:Dim strMachines,aMachines,machineDim objPing,objStatus,objws
Dim connect,unconnect
Do
Machine="www.baidu.com"
Set objPing=GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & machine & "'")
connect=0
unconnect=0
For i=1 To 10
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
unconnect=unconnect+1
Else
connect=connect+1
End If
Next
Next
If connect=10 Then
MsgBox "开网啦!"
WScript.Quit
elseif connect=0 then MsgBox "断网啦!"
WScript.Quit
End If
WScript.Sleep 3*1000
Loop AU3代码:Dim $strMachines,$aMachines,$machine
Dim $objPing,$objStatus,$objws
Dim $connect,$unconnect
$Machine="www.baidu.com"
$objPing=objGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$objPing.ExecQuery("select * from Win32_PingStatus where address = '" & $machine & "'")
$connect=0
$unconnect=0
For $i=1 To 10
For $objStatus in $objPing
If $objStatus.StatusCode="" or $objStatus.StatusCode<>0 Then
$unconnect=$unconnect+1
Else
$connect=$connect+1
EndIf
Next
MsgBox(0,"",$connect)
Next
If $connect=10 Then
_GetDHCPstatus()
GUICtrlSetColor($chk, 0xFF0000)
elseif $connect=0 then
GUICtrlSetData($chk,"没有连接到外网")
EndIf Dim $strMachines,$aMachines,$machine
Dim $objPing,$objStatus,$objws
Dim $connect,$unconnect
$Machine = "www.baidu.com"
$obj = ObjGet("winmgmts:{impersonationLevel=impersonate}")
$objPing = $obj.ExecQuery("select * from Win32_PingStatus where address = '" & $machine & "'")
$connect=0
$unconnect=0
For $i=1 To 10
For $objStatus in $objPing
If $objStatus.StatusCode <> '' or $objStatus.StatusCode <> 0 Then
$unconnect += 1
Else
$connect += 1
EndIf
Next
Next
If $connect=10 Then
MsgBox (0,'',"开网啦!")
ElseIf $connect=0 then
MsgBox (0,'',"断网啦!")
EndIf
Exit 在au3中需要调用WMI去ping网站?
页:
[1]