I'm trying to pass a variable from a batch file to an hta which needs to be displayed in a pop up window of some sort - either html or vbscript.
The computer name is looped through a batch file which opens individual instances so all I would need to pass is the variable "%1".
What I'm needing is a way to either bring that variable over to VBscript or Javascript, then print via html.
You can use CommandLine
property of your HTA appliction object (i.e. its ID
).
It contains full verbatim command line with your HTA filename (and possibly path) followed by arguments you supplied when running the HTA
This means you can pass arguments through the command line of your HTA, for example:
start "" "c:\your-path\your-app.hta" "%~1"
"%~1"
ensures that the first parameter is always in double-quotes irregardless original %1 having them or not. This works only in an actual batch file.
How to extract first commandline argument:
CommandLine
is "
"
" "
) or tab ("\t"
)"
"
- your argument is between the double-quotes" "
, "\t"` or end-of-stringAll of this can be done manually or with the help of regular expressions
Since you are the one who runs the HTA you could in theory exclude code that runs in absence of double-quotes by always including them on the command line, although this is not recommended
For more info see this article about passing parameters to HTA, it also includes example VBS code