Set oArgs = WScript.Arguments For i = 0 to oArgs.Count - 1 WScript.Echo oArgs(i) Next
关于参数解析,这里给出一个Windows 2000 support tools中的一个脚本的例子。你可以复用这个函数,以解析任何以/ArgName:Value形式指定的参数。
' searches for and returns the value of a command line argument of the form ' /argName:value from the supplied array. erases the entry in the array so ' that only untouched entries remain.
function GetArgValue(argName, args()) dim a dim v dim argNameLength dim x dim argCount dim fullArgName
' Get the length of the argname we are looking for argNameLength = Len(fullArgName) GetArgValue = "" ' default to nothing
for x = 0 To argCount if Len(args(x)) >= argNameLength then
a = Mid(args(x), 1, argNameLength) if UCase(a) = UCase(fullArgName) then
' erase it so we can look for unknown args later v = args(x) args(x) = ""
if Len(v) > argNameLength then GetArgValue = Mid(v, argNameLength + 1) exit function else GetArgValue = "" exit function end if end if end if next end function
Sub Include(sInstFile) Dim oFSO, f, s Set oFSO = CreateObject("Scripting.FileSystemObject") Set f = oFSO.OpenTextFile(sInstFile) s = f.ReadAll f.Close ExecuteGlobal s End Sub
Sub Include(sInstFile) Dim oFSO, f, s Set oFSO = CreateObject("Scripting.FileSystemObject") Set f = oFSO.OpenTextFile(sInstFile) s = f.ReadAll f.Close ExecuteGlobal s End Sub
使用的时候,这个把这个sub放在代码里,然后用 Include "comm.vbs" 这样来包含以下就可以了