首页 > 解决方案 > 将命令行参数传递给 HTA 应用程序

问题描述

我有一个想从命令提示符运行的 HTA 应用程序。我已经尝试了我能想到的所有方法,但它不起作用!它只是启动应用程序,仅此而已。

从命令提示符中,我使用完整路径运行它:

C:\users\xxx\script.hta "arg1" "arg2"

这基本上是我在这里想要完成的?

我在这里浏览了许多类似问题的页面,但我想我只是没有正确地将它们组合在一起!

这是代码:

<html>
<head>
<HTA:Application
    ID="oHTA"
    APPLICATIONNAME="MSI-BUILD"
    Border = "NO"
    Singleinstance ="YES"
    BorderStyle = "Complex"
    ShowInTaskBar = "YES"
    MaximizeButton = "No"
    MinimizeButton = "No"
    scroll="NO"
    VERSION="2"

 />

<script language = "VBScript">

    Sub RunProgram  

    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8

    Set objShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = CreateObject("WScript.Shell")


    strCurDir= WshShell.CurrentDirectory

    StrARG = MSINAME.value
    StrARG3 = FPath.value

    strFolder = "D:\SMPSS\PROJECTS\"&MSINAME.value

    Set oFSO = CreateObject("Scripting.FileSystemObject")

    If Not oFSO.FolderExists(strFolder) Then
    oFSO.CreateFolder strFolder
    End If


    objShell.Run "D:\SMPSS\MSI-2\1-newproject.vbs " & StrARG , 0, True

    window.close() 

End Sub

Sub Window_onLoad

    Self.Resizeto 890, 300
    document.title = oHTA.applicationName & " v" & oHTA.version

    arrCommands = Split(oHTA.commandLine, chr(34))
    For i = 3 to (Ubound(arrCommands) - 1) Step 2
        Select Case arrCommands(i)
                Case "arg1" 
                    myarg1 = "This is argument 1."
                Case "arg2"
                    myarg2 = "This is argument 2."
        End Select
    Next
    MsgBox myarg1
    MsgBox myarg2

End Sub

</script>
</head>
<body style="background-color: #b2b2f4">

        <td>MSI-NAME:</td>
        <td>&nbsp;</td>
        <td style="overflow:hidden">
        <td style="resize:none">
        <td style="text-align:right">
        <td style="width: 325px"><input type = "text" name = "MSINAME" id = "MSINAME" size="50" /></td>
        <p>
        <td>PATH:</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="overflow:hidden"></td>
        <td style="resize:none"></td>
        <td style="text-align:right"></td>
        <td style="width: 325px"><input type = "text" name = "FPath" id = "FPath" value ="" size="50" /></td>
        <td>&nbsp;</td>
        </p>
        <p>
        <input id='submit' type="button" value="Submit" onClick="RunProgram"></td>
        </p>
</body>
</html>

标签: cmdvbscriptcommand-line-argumentshta

解决方案


我发现问题出<meta http-equiv="x-ua-compatible" content="ie=9">在我的代码中,一旦删除一切都开始工作,应该感谢!此外,该文件未保存为 ANSI,因此存在无效字符错误。现在一切都很好!


推荐阅读