我的也很类似。
'使用Ping.exe检测机器是否在线2 @- J& V0 q- r' }- ~9 L
'******************************************************************************
3 o( Z9 l: d r, DFunction Ping(strComputer)1 }) b/ D. Z( x, o; @, U; c0 U1 p( T
& l; E& a, n% A; \, ZDim objShell,objExecObject,strText
( y+ e2 U$ D+ I x3 D; }3 N
- O% Z) k, }- ~ Set objShell = CreateObject("WScript.Shell")0 m3 F/ x& B8 B( o% A) T7 Z% @
Set objExecObject = objShell.Exec ("ping -n 1 -w 2 " & strComputer)
5 ?# t; {6 ~. k/ a1 C9 I7 } Do While Not objExecObject.StdOut.AtEndOfStream4 S. ^7 h6 X- C4 A% ]0 |$ M# _
strText = objExecObject.StdOut.ReadAll()1 W' w" I% D" w
If Instr(strText, "Reply") > 0 Then
7 [; e5 ?+ Q& l+ Z) X Ping = 1
* v6 b* O" T* I% }, U Else0 m" ^1 S! j k9 ]- p
Ping = 0
G* V1 R% S% K U End If. T/ ^$ ?' O% u. n9 k4 Q9 |9 Y8 _
Loop
- ^. D' H; `* n" k% d& F, X
+ B/ ~- L k& [$ fEnd Function( Q2 k; A! c" z+ C
'******************************************************************************
& ~" L, V# L! Y'End Of Function
) D! `# q. z' o1 _/ k: e1 q9 I1 y/ y% @% v r- {; B( H
0 P( m3 V+ g6 t7 @* t! z8 k'使用WMI,检测机器是否在线,需要在XP或者2003机器上执行
( a: x+ i# D( ~'******************************************************************************+ _9 ^, \. ]- x! k- \) U M6 _
Function PingStatus(strComputer)1 ^, c& L' |) p+ b) d2 `
) v1 ~- o9 d7 V Dim objWMIService,objPing,colPings
* H7 ^! J! x: _0 J& c% V) @
2 I9 ], m- J& S2 U( t3 f6 Z5 v Set objWMIService = GetObject("winmgmts:" _$ G' g4 r% b6 G4 `# v, b. l
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
' a; @5 F F) t3 J9 _ Set colPings = objWMIService.ExecQuery _2 M" U+ x" Z7 m9 `% D( g
("Select * From Win32_PingStatus where Address = '" & strComputer & "'")
- H% X4 B' I& C1 V: O" ?$ `3 M( \ For Each objPing in colPings
& w! p @, d# e! n, B7 r2 C If objPing.StatusCode = 0 Then
5 w l( w3 w( c3 Z/ P) | PingStatus = 1
* I2 m) }$ c+ U4 N, A* B Else8 d0 r$ ^) r2 @) d7 t
PingStatus = 0
$ S' U2 i. ~: [! f6 i( [" v: K End If$ X0 I ?, _ G; V
Next8 Q7 P9 n' u. c, v
: B6 Y# H$ E5 V$ R/ M. |End Function" N Y- E% }7 {+ ]- m. ?0 c. z3 U
'******************************************************************************