Solved

Getting command line arguments in VBScript running as a VBS file

Posted on 2001-07-14
2
1,553 Views
Last Modified: 2007-11-27
Hello All,
 I would like to write a VBS file, which takes some arguments on the command line

cscript myvvbsfile.vbs arg1 arg2 arg3

How do I retrieve this arguments in VBS?

Thanks in advance,
Nicholas Waltham
0
Comment
Question by:nwaltham
2 Comments
 
LVL 15

Accepted Solution

by:
robbert earned 30 total points
Comment Utility
There is the (zero-based) Arguments collection:

For i = 0 To cscript.arguments.count - 1
    x = cscript.arguments(i)
Next

For Each arg In cscript.arguments
    x = arg
Next

WSH reference
http://msdn.microsoft.com/scripting/windowshost/doc/wshtoc.htm
WSH arguments
http://msdn.microsoft.com/scripting/windowshost/doc/wsObjWshArguments.htm
0
 

Expert Comment

by:caller9
Comment Utility
This is a great answer but didn't work for me. Replace the cscript with wscript like so:

For Each arg In wscript.arguments
   x = arg
Next

This worked like a charm for me.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now