سؤال

Is it possible to call an .HTA app hosted on an internal web site (intranet) and pass in arguments/parameters using standard "?var=value" and "&var=value" syntax? I know it's possible to launch them using WScript-like syntax like "app.hta arg1 arg2...". But I can't seem to get the spaces to work properly even when parsing as %20, etc.

هل كانت مفيدة؟

المحلول

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top