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
这一节里,介绍了由单个脚本文件组装成一个较大的工程的四种方法,通过运用这些方法,你可以建立自己的常用函数库,在各个脚本之间共享变量和传递数据,等等。 在网上找到一段实现的代码,在这次的项目中起了大作用了。用vbs实现很多复杂的业务时,需要把一些公共的函数,class等写在一个公共的可复用的vbs文件里,像个库一样,其他的脚本都包含这个库的脚本。 复制代码 代码如下: 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" 这样来包含以下就可以了 当前1/2页 12下一页