Sunday, May 17, 2009

Run a Visual Basic Script Program from a command prompt

A Visual Basic script program can be run from a DOS prompt. cscript command can be used for this purpose.

C:\>cscript <pathToVBScriptFile>

by default cscript command displays the Microsoft Header but this can be avoided by providing /nologo argument.

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\>cscript /nologo <pathToVBScriptFile>

User can also take control to take input and display the output on the console. For that user had to use following options in the VB Script.

dim input
dim output
dim name

set output = wscript.stdout
set input = wscript.stdin

output.write "Enter Your Name : "
name = input.readline

output.writeline "Your Name is " & name

No comments: