You can pass commandline args to HTAs by specifying a path such as C:\helloworld.hta "arg1"
. Below is an example, save it to a directory and run it using this syntax C:\helloworld.hta "admin" "user"
Ensure you surround the arg with quotes, the code in this script uses the Split Function
to split the commandline at the quotes.
<html>
<head>
<title>Hello World with Args</title>
<HTA:APPLICATION
APPLICATIONNAME="Hello World with Args"
ID="HelloWorldwithArgs"
VERSION="1.0"/>
</head>
<script language="VBScript">
Sub Window_OnLoad
Window.resizeTo 400, 300
args = Split(HelloWorldwithArgs.commandLine, Chr(34))
For i = 3 To (UBound(args) - 1) Step 2
Select Case LCase(args(i))
Case "admin"
strAdmin = "Hello World!!" & vbCrLf & "You passed the admin arg."
Case "user"
strUser = "Hello World!!" & vbCrLf & "You passed the user arg."
End Select
Next
DataArea.innerHTML = strAdmin & vbCrLf & strUser
End Sub
</script>
<body bgcolor="white">
<h1 align="center">Hello World</h1>
<textarea align="center" name="DataArea" id="DataArea" rows="5" cols="40"></textarea><br /><br />
<input type="button" style="width:100px;" name="btnExit" id="btnExit" value="Exit" onclick="self.close()">
</body>
</html>