【问题标题】:VBScript/HTA Application - Running multiple programs at once chosen by userVBScript/HTA 应用程序 - 一次运行由用户选择的多个程序
【发布时间】:2014-01-31 21:59:37
【问题描述】:

所以这就是我对男孩和女孩的疑惑——首先,我对此完全是个菜鸟,从字面上看,这才刚刚开始,所以不要对我太苛刻。我写了一堆代码来制作一个 .HTA 应用程序:

> <html> <head>
> 
> <script type="text/vbscript">
> 
> Dim objShell Sub Button1_OnClick()
> 
> if box2.checked AND box1.checked then
> 
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
> 
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
> 
> elseif box1.checked then
> 
> Set objShell = CreateObject( "WScript.Shell" ) objShell.Run("cmd.exe")
> Set objShell = Nothing
> 
> Elseif box2.checked then
> 
> Set objShell = CreateObject( "WScript.Shell" )
> objShell.Run("""%programfiles(x86)%\Mozilla Firefox\firefox.exe""")
> Set objShell = Nothing
> 
> 
> End If End Sub
> 
> 
> </script> </head> <body> <font face=Calibri> Check the program you
> would like to run! <br> Available programs to run for now: <br> <input
> type="checkbox" name="box1">CMD <br> <input type="checkbox"
> name="box2">Mozilla <br> <i>Choose which program(s) you'd like to run.
> It is possible to run multiple programs at one time!</i></font><br>
> <input type="button" name="btn1" onclick="Button1_OnClick"
> value="Submit"><br> <div id="error"></div>
> 
> 
> 
> </body> </html>

这完全符合预期,当我检查两个程序时,它们都会运行,当我检查其中一个时,只有一个会运行。但是,如果我在该列表中有 50 个不同的程序怎么办?我想有一种比为每个程序组合编写 if/else/elseif 语句负载更简单的方法来编写它吗?如上所述,我对此完全不熟悉,也许我还没有找到更简单的方法......但这也是我问的原因。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您可以将元素属性用于您的目的。
    遍历所有复选框,然后使用存储在自定义属性中的路径(如果已选中)启动该过程。完成。

    <html>
    <head>
        <script type="text/vbscript">
            Dim objShell
            Set objShell = CreateObject("WScript.Shell")
    
            Sub StartProcesses
                Dim Checkbox
                For Each Checkbox In Document.getElementsByName("process")
                    If Checkbox.Checked Then
                        objShell.Run """" & Checkbox.getAttribute("path") & """"
                    End If
                Next
            End Sub
        </script>
    </head>
    <body>
        <font face=Calibri>
            Check the program you would like to run! <br>
            Available programs to run for now: <br> 
            <div id="ProcessList">
                <input type="checkbox" name="process" path="cmd.exe">CMD <br>
                <input type="checkbox" name="process" path="iexplore.exe">Internet Explorer <br>
                <input type="checkbox" name="process" path="%programfiles(x86)%\Mozilla Firefox\firefox.exe">Firefox <br>
                <input type="checkbox" name="process" path="calc.exe">Calculator <br>
                <input type="checkbox" name="process" path="notepad.exe">Notepad <br>
            </div>
            <i>Choose which program(s) you'd like to run. It is possible to run multiple programs at one time!</i>
        </font><br>
        <input type="button" onclick="StartProcesses" value="Submit"><br>
        <div id="error"></div>
    </body>
    </html>
    

    【讨论】:

    猜你喜欢
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多