Getting command line arguments in VBScript running as a VBS file

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
Who is Participating?
robbertConnect With a Mentor Commented:
There is the (zero-based) Arguments collection:

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

For Each arg In cscript.arguments
    x = arg

WSH reference
WSH arguments
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

This worked like a charm for me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.