Creating a Useful Error Message--Arguments

上一篇 / 下一篇  2010-03-26 20:59:17 / 个人分类:VBScript

Command-Line Arguments

Command-line arguments provide you with the ability to modify the execution of a script. prior to running it.

 

CheckArgsPingMultipleComputers.vbs

Option Explicit
On Error Resume Next
Dim strComputer
Dim aMachines,machine
Dim objPing,objStatus


strComputer = WScript.Arguments.Item(0)
aMachines = Split(strComputer, ",")
For Each machine In aMachines
Set bjPing = GetObject("winmgmts:{impersonationLevel = impersonate}"). _
ExecQuery("select * from Win32_PingStatus where address = '" _
& machine & "'")
For Each objStatus In objPing
If IsNull(objStatus.StatusCode) Or objStatus.StatusCode<>0 Then
WScript.Echo ("mahine" & machine & "is not reachable")
Else
WScript.Echo ("reply from" & machine)
End If
Next
Next
Sub subCheckArgs
If WScript.Arguments.Count = 0 Then
WScript.Echo "You must enter a computer to ping" & VbCrLf & _
"Try this: Cscript. CheckArgsPingMultipeComputers.vbs" & "127.0.0.1;localhost"
WScript.Quit
End If
End Sub

 

From

Microsoft@ VBScript. Step by Step
By Ed Wilson

 

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar