2013-12-23 90 views
0

我需要通過一個參數啓動一個vbs script並與傳入的參數相關,請參閱彈出窗口。Vbscript使用參數啓動vbs並定義多個參數

例子:

Dim Arg, var1, var2 
Set Arg = WScript.Arguments 

'Parameter1, begin with index0 
var1 = Arg(0) 



if (instr(WScript.Arguments.Name,"Printer")> 0 then 
wscript.echo "Printer type..." 
end if 

if (instr(WScript.Arguments.Name,"help")> 0 then 
wscript.echo "help..." 
end if 

在此先感謝

'Clear the objects at the end of your script. 
set Arg = Nothing 

回答

0

調用你的腳本,像這樣

myscript.vbs /help 

和訪問ARGS像這樣

'setup the named argument collection 
set argNamedCollection = WScript.Arguments.Named 


'get the arguments passed in 
argHelp = argNamedCollection.Item("help") 
argPrinter = argNamedCollection.Item("printer") 

     'or check directly 
'check for help arguments 
if argNamedCollection.Exists("help") then 
    'do somthing 
end if