No announcement yet.

VBScript Argument --help

  • Filter
  • Time
  • Show
Clear All
new posts

  • VBScript Argument --help

    I have written some VBScript in wsf and am looking for a good way to handling the arguments. I know that the XML named arguments can be a little helpful, really just for free help usage, but I don't want the program to just be able to handle /h and /help but also unix style arguments like -h and --help.

    I figure I will have to write this myself in VBS, but I was wondering if anyone had a good way of doing this, short of having to have 2 separate sections, one for /help style processing and one for --help or -h style processing.

    What I have thought of so far is doing the named arguments first as usual, and then doing a separate loop though all WScript.Arguments for the -h and --help style arguments, but considering that I want each /option to have a corresponding -option and --option style as well, this means that there will be a lot of duplicate lines which strikes me as not the best way of attacking the problem or maintaining the code if I changes things.

    Q1. Does anyone have a better way of handling all these arguments together to avoid duplication?

    There are 2 other bugs I have found in the default way of handling arguments with VBS/Wsf:

    Q2. When I type
    cscript scriptname.wsf /option1:something /randominvalidoption
    I notice that it doesn't catch the /randominvalidoption and just silently ignores it. I would like an unrecognized option to trip the help usage. So far all I can think of is again cycling through all arg in a case select or something.

    Q3. I have changed the default action for the WSF file type to be the Console Based Windows Script Host, but when running
    scriptname.wsf /arg1 /option1:something
    it does not pass the options and arguments to the script. This is odd really, since even if I were to run
    wscript scriptname.wsf /arg1 /option1:something
    it actually does pass the arguments. What's even more strange is that if I put WSF back to the Windows Based Script Host by default, and run it again, it passes all the arguments.

    I can't quite figure out this "feature" since running either cscript scriptname.wsf.... or wscript scriptname.wsf .... does pass arguments to the script...

    So,to summarize my questions:

    Q1. What's the best way of handling /help or /server:NAME as well as --help or --server NAME style arguments?

    Q2. How to catch unrecognized switches to print usage and exit?

    Q3. Why do args not get passed when called scriptname.wsf without a preceding scripthost program, but only when cscript is the default?

  • #2
    Re: VBScript Argument --help

    The unnamed argument must be listed befor named arguments.


    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts