Is there a %*
(batch files) or $*
(bash script) argument list equivalent for VBScript ?
I want to retrieve the exact command line invocation.
Contrived example:
cscript //nologo script.vbs /arg1:a -s "a b" 1 c /arg2:"x y" "d e" -l '3 4'
should return:
/arg1:a -s "a b" 1 c /arg2:"x y" "d e" -l '3 4'
(including the quotes).
I have looked at WScript.Arguments
but it doesn't return the verbatim command line.
There is no equivalent to
%*
or$*
in VBScript. TheWScript.Arguments
collection hides the input command line, giving access to the arguments as items inside collections.The only way I know to retrieve the required information is to query WMI for the current process and from the process information read the command line.
This will give you the full command line used to start the current script.
There isn't one. But it's fairly trivial.
or
And
This applies to VBScript and VBA.
Both of these basics are hosted by other programs. It is the host that collects commandline information (if any). It is the host that makes it available to vbs via an object in wscript's case, but not in when hosted in IE/IIS. And VBA has a host implemented Function (implemented by Corel Office, Microsoft's office, and VB6).
Under the hood (I've removed no parsing behaviour paragraphs) (and note ANSI/Unicode differences)
CommandLineToArgvW Function
Parses a Unicode command-line string and returns an array of null-terminated Unicode strings containing the individual arguments found in that command line as well as a count of arguments, similar to the standard C run-time argv and argc values.
Syntax
Parameters
This function accepts command lines containing a program name that is either enclosed in quotation marks or not enclosed in quotation marks.
CommandLineToArgvW has a special interpretation of backslash characters when they are followed by a quotation mark character ("), as follows:
2n backslashes followed by a quotation mark produce n backslashes followed by a quotation mark.
(2n) + 1 backslashes followed by a quotation mark again produce n backslashes followed by a quotation mark.
n backslashes not followed by a quotation mark simply produce n backslashes.
GetCommandLine
Retrieves the command-line string for the current process.
ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type.
To convert the command line to an argv style array of strings, call the CommandLineToArgvW function.
Note The name of the executable in the command line that the operating system provides to a process is not necessarily identical to that in the command line that the calling process gives to the CreateProcess function. The operating system may prepend a fully qualified path to an executable name that is provided without a fully qualified path.