VBScript Argument –help

Home Forums Scripting General Scripting VBScript Argument –help

Viewing 1 post (of 1 total)
  • Author

  • humbletech99

    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?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

13 Email Threat Types to Know About Right Now

As email threats evolve and multiply, keeping track of them all—and staying protected against the many different types—becomes a complex challenge. Today, that requires more than just the traditional email gateway solution that used to be good enough.

In this eBook you will learn:

  • What are the most common and challenging email attacks for organizations?
  • How to defend against sophisticated email threats, such as spoofing, social engineering, and fraud
  • How to protect employees at the inbox level with the right technologies and security-awareness training
  • How to use a multilayered protection strategy to reduce susceptibility to email attacks and better defend your business and employees

Sponsored by: