Pass variables to a Windows Scripting Host file

This article shows how to pass user-defined parameters to a windows scripting host file from a command line.

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 29
February 05, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

I (Steve Schofield) was recently was working on how to pass command line variables to a VBS file.  This article shows how to pass user-defined parameters to a Windows Scripting Host file from a command line.

Example of what would be typed at the command line

 

wscript filename.vbs parameter1 parameter2

 

In the command line this needs to start with wscript (VBScript interpreter) or cscript (JScript compiler).  Filename.vbs (Name of the file.  VBS and JS can be the extensions) and separated by spaces parameter1, parameter2 etc.  Make sure the parameters have spaces between them. 

Retrieve parameters from File

Using the Args statement helps retrieve the space delimited array of parameters that were executed in the command line. 

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

'First parameter
var1 = ArgObj(0)
'Second parameter
var2 = ArgObj(1)
msgbox "Variable 1=" & var1 & " Variable 2=" & var2

'Clear object out of memory
set ArgObj = Nothing

Batch file to execute file

Either a .bat or .cmd file can be used to execute the file.  Another technique would be to use Windows Task Scheduler to schedule this file to be executed on a timed basis.

mybatchfile.cmd

wscript filename.vbs Parameter1 Parameter2

blog comments powered by Disqus
WINDOWS SCRIPTING ARTICLES

- More Windows Scripting Workarounds from Nilpo
- Overloading Methods and More in VBScript
- Improving MFC for Windows Vista
- Regular Expressions in VBScript
- Working with Dates in WMI
- Completing Calendars with VBScript Date Func...
- Building Calendars with VBScript Date Functi...
- Working With Dates and Times in VBScript
- Designing WCF DataContract Classes Using the...
- Understanding Dates and Times in VBScript
- Working With Arrays in VBScript
- Compressed Folders in WSH
- Using .NET Interops in VBScript
- Nilpo`s Scripting Secrets, Vol I
- Database operations using Silverlight 2.0 WC...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials