System Administration Scripting

2007年4月11日星期三

检查各工作站是否开机并有何人登陆使用

On Error Resume Next

arrComputers = Array("WORKSTATION001","WORKSTATION002","WORKSTATION003","WORKSTATION004", _
"WORKSTATION005","WORKSTATION006","WORKSTATION007","WORKSTATION008", _
"WORKSTATION009","WORKSTATION010","WORKSTATION011","WORKSTATION012", _
"WORKSTATION013","WORKSTATION014", "WORKSTATION15","WORKSTATION016", _
"WORKSTATION017","WORKSTATION018","WORKSTATION019","WORKSTATION020")

For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objShell = WScript.CreateObject("WScript.Shell")

If IsOnline(strComputer) Then
WScript.Echo strComputer & " is Online."
strCommand = "psloggedon.exe -x \\" & strComputer
Set objExec = objShell.Exec(strCommand)
'strInfo = Replace(objExec.StdOut.ReadAll(), vbCrLf, "")
strInfo = objExec.StdOut.ReadAll()
WScript.Echo strInfo
Else
Wscript.Echo strComputer & " is Offline."
End If
Next

Function IsOnline(strPC)
IsOnline = false
strCmd = "%comspec% /c ping -n 2 -w 500 " & strPC & ""
Set objExecObject = objShell.Exec(strCmd)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
If Instr(strText, "Reply") > 0 Then
IsOnline = true
End If
Loop
End Function

Bookmark this post:
Ma.gnolia DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google


0 评论:

相关文章

©2007