Question

I'm using a HTA and I want to make various buttons to open different programs on the system.

I've managed to get one program to run via the runfile command but how do I write to open another program using a separate button such as MS Word for example.

<html>
<head>
    <title>Start Screen</title>
    <HTA:APPLICATION ID="startscreen"
              APPLICATIONNAME="startscreen"
                BORDER="thin"
                BORDERSTYLE="normal"
                CAPTION="yes"
                ICON="ss.ico"
                MAXIMIZEBUTTON="no"
                MINIMIZEBUTTON="yes"
                SCROLL="no"
                SHOWINTASKBAR="yes"
                SINGLEINSTANCE="yes"
                SYSMENU="yes"
                VERSION="1.0"
                Navigable ="yes"
                WINDOWSTATE="normal"
                contextmenu="no" />
    <script type="text/javascript" language="javascript">
        function RunFile() {
        WshShell = new ActiveXObject("WScript.Shell");
        WshShell.Run("c:/windows/system32/notepad.exe", 1, false);
        }
    </script>
</head>
<body>
    <input type="button" value="Run Notepad" onclick="RunFile();"/>
</body>
</html>
Était-ce utile?

La solution

You can use this

function RunFile(path) {
    WshShell = new ActiveXObject("WScript.Shell");
    WshShell.Run(path, 1, false);
}

 

<input type="button" value="Run Notepad" onclick="RunFile('c:\windows\notepad.exe');"/>
<input type="button" value="Run Paint" onclick="RunFile('c:\windows\system32\mspaint.exe');"/>

Or a different approach. Create variables for app path

var notepad = "c:\windows\notepad.exe";
var paint = "c:\windows\system32\mspaint.exe";

and pass them to the function

<input type="button" value="Run Notepad" onclick="RunFile(notepad);"/>
<input type="button" value="Run Paint" onclick="RunFile(paint);"/>

Autres conseils

How about

<input type="button" value="Run Notepad"  
    onclick="RunFile('c:/windows/system32/notepad.exe');"
/>

and the appropriate modification of the RunFile() function?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top