Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate vbScript argument names

I am calling a vbScript from PowerShell, with arguments that are defined in a text string, and I want to validate that the arguments being used are correct. Say my valid arguments are ARG1, ARG2 & ARG3, and someone has a string of "/ARGG1:one /ARG2:two", I want to validate the named arguments against an array of valid arguments and catch that ARGG1. Where I am failing is in getting the names of the named arguments. I can reference a particular named argument with WScript.Arguments.Named("ARG1") for example. But I can't seem to loop through WScript.Arguments.Named and return the actual argument names used. Something like this

For Each Argument In WScript.Arguments.Named
    msgBox Argument.name
Next
like image 592
Gordon Avatar asked Jan 20 '26 05:01

Gordon


1 Answers

When iterating the Named argument collection you are accessing the key (argument name) not the WshNamed object itself. If you pass the key back into the collection you will be able to access the value for that Named Argument.

Dim key
For Each key In WScript.Arguments.Named
    Dim argument: argument = WScript.Arguments.Named.Item(key)
    Call WScript.Echo(key) 'Return argument name
    Call WScript.Echo(argument) 'Return argument value
Next

Output:

ARG1
one
ARG2
two
like image 135
user692942 Avatar answered Jan 23 '26 20:01

user692942



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!