Validate vbScript argument names

 ̄綄美尐妖づ 提交于 2021-01-27 18:43:49

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/60446977/validate-vbscript-argument-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!