Solved

Getting command line arguments in VBScript running as a VBS file

Posted on 2001-07-14
2
1,563 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
robbert earned 30 total points
ID: 6281870
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
ID: 7909202
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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