Developer's Closet A place where I can put my PHP, SQL, Perl, JavaScript, and VBScript code.

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

Call VBScript from a Windows Batch Script

This very easy bit of code will call a VBScript script from a Windows Batch Script:

call script.vbs

Output the Date in a Windows Batch Script

This simple script will output the date in the MMDDYYYY format. The script can be used to enhance other scripts, for log files, etc.

@echo off
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY
@REM The date variable will be in the MMDDYYYY format so it can be called later in the script

FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%

@echo on
echo hello %date%