Pass Parameters from a Windows Batch Script to VBScript

It can be very useful to pass parameters from a Windows Batch Script to VBScript. For this to work, a user will pass parameters to a batch script, the batch script will pass them to the VBScript script using cscript and the script will output the results. This will allow you to use the power of VBScript within the simple framework of a batch script.

Create a batch script named Call.bat. Add this code to the script:

cscript Script.vbe %1 %2

Create a VBScript script named Script.vbe. Add this code to the script:

Option Explicit
Dim args, strOutOne, strOutTwo
set args = Wscript.arguments

strOutOne= args(0)
strOutTwo= args(1)

WScript.Echo strOutOne
WScript.Echo strOutTwo

Finally, run the batch script:

Call.bat hello world

Leave a Reply