Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using command line arguments in VBscript

How can I pass and access command line arguments in VBscript?

like image 550
Sunil Avatar asked Mar 18 '10 12:03

Sunil


People also ask

How do I run an argument from the command line?

option. You can test command line arguments by running an executable from the "Command Prompt" in Windows or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run.

Can you run VBScript in CMD?

I googled it & got to know that we can run VBScript from command line by executing below command: For Example my vbscript name is Converter. vbs & it's present in folder D:\VBS .


2 Answers

Set args = Wscript.Arguments  For Each arg In args   Wscript.Echo arg Next 

From a command prompt, run the script like this:

CSCRIPT MyScript.vbs 1 2 A B "Arg with spaces" 

Will give results like this:

1 2 A B Arg with spaces 
like image 172
aphoria Avatar answered Sep 28 '22 20:09

aphoria


If you need direct access:

WScript.Arguments.Item(0) WScript.Arguments.Item(1) ... 
like image 40
Jerther Avatar answered Sep 28 '22 19:09

Jerther