locked
Why does WScript.Arguments not return the command line arguments? RRS feed

  • Question

  • Here is the entire VBScript:

    [code]
    dim cmdArgs

    set cmdArgs = WScript.Arguments

    WScript.Echo cmdArgs.length
    [/code]

    Here is the command line and output:

    C:\temp\Test>test3 One Two Three
    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    0

    C:\temp\Test>

    The operating system is Microsoft Windows XP Professional, Version 2002, Service Pack 3.

    As you can see from the output the cmdArgs object is set presumably to WScript.Arguments.  But despite there being 3 arguments passed to the script zero are reflected in either the length or count property.

    WHY?  How do I get Windows to work?


    Scaling the Cliffs of Insanity
    • Moved by Harry Zhu Monday, January 18, 2010 9:08 AM (From:JScript for the .NET Framework)
    Wednesday, January 13, 2010 6:40 PM

Answers

  • This question should should probably be posted here:

    http://social.technet.microsoft.com/Forums/en-US/ITCG/threads

    However, when I tested your script it worked fine for me. Both the Length and the Count properties of the Wscript.Arguments object have the value 3 when I pass three arguments to the script.

     


    Richard Mueller - MVP Directory Services
    Tuesday, June 7, 2011 10:42 PM
  • If you have one of the Visual Studio packages installed you can run the following command and choose to debug in VS:

    cscript.exe //d //x test3.vbs 1

    This will allow you to look specifically at the Locals window to see if you can spot something amiss in your environment.  Here is a KB providing steps on how to debug

    http://support.microsoft.com/kb/308364

    Using the code you provided above, I was able to run this script fine with the 5.8 engine using both wscript and cscript.  Have you tried running on a different machine?

    Tuesday, June 7, 2011 11:28 PM

All replies

  • Hi,

    The question relating to VBScript is beyond the scope of this forum, I 'm moving the thread to : where is the forum for... forum.

    The experts there will direct you to the right place for the question .

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, January 18, 2010 9:08 AM
  • Harry,

    I don't doubt that I entered this question on the wrong forum.  There are many to choose from on this site and choosing the right one can be a challenge.  But if you feel it should be on a different forum, can you post a link to the forum you moved it to so I could find it?

    Thanks,

    Maineac


    Scaling the Cliffs of Insanity
    Tuesday, June 7, 2011 5:44 PM
  • This question should should probably be posted here:

    http://social.technet.microsoft.com/Forums/en-US/ITCG/threads

    However, when I tested your script it worked fine for me. Both the Length and the Count properties of the Wscript.Arguments object have the value 3 when I pass three arguments to the script.

     


    Richard Mueller - MVP Directory Services
    Tuesday, June 7, 2011 10:42 PM
  • If you have one of the Visual Studio packages installed you can run the following command and choose to debug in VS:

    cscript.exe //d //x test3.vbs 1

    This will allow you to look specifically at the Locals window to see if you can spot something amiss in your environment.  Here is a KB providing steps on how to debug

    http://support.microsoft.com/kb/308364

    Using the code you provided above, I was able to run this script fine with the 5.8 engine using both wscript and cscript.  Have you tried running on a different machine?

    Tuesday, June 7, 2011 11:28 PM