none
Open program from HTA RRS feed

  • Question

  • Hello

    Im trying to create a HTA application, that can open programs(exe, bat etc..) locally on the computer.

    This will be used on a Kiosk PC, where the users don't have access to the desktop etc.

    But have some problems with finding a script that works with my existing code..

    Right now I'm using this script to open the programs:

    <script type="text/javascript">
        function runApp(which) {
        WshShell = new ActiveXObject("WScript.Shell");
        WshShell.Run (which,1,true);
        }
    </script>

    And this is how my links looks:

    <a 
    href="javascript:window.location.href=window.location.href" 
    onclick="runApp('file://C:/Tools/program.exe');parent.playSound('assets/sounds/startsound.mp3');"
    onmouseover="playSound('assets/sounds/hover.wav');"
    unselectable="on"
    style="cursor: hand; display: block;">Start Program
    </a>

    The problem with this script, is that some of the programs I open from the launcher HTA, are placed below the HTA app that runs in fullscreen.. So the users need to ALT+TAB to switch to them.. This not is not good, since most of the users don't know what to do..

    I have then been searching for another script, and found this HTA sample, which looks like a better way to do it:

    <!DOCTYPE html>
    <html>
    <head>
    
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    
    <HTA:APPLICATION
    APPLICATIONNAME="Open link with chrome browser"
    BORDER="THIN"
    BORDERSTYLE="NORMAL"
    ICON="Explorer.exe"
    INNERBORDER="NO"
    MAXIMIZEBUTTON="NO"
    MINIMIZEBUTTON="NO"
    SCROLL="NO"
    SELECTION="NO"
    SINGLEINSTANCE="YES"/>
    <META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
    <title>Test HTA</title>
    <SCRIPT LANGUAGE="VBScript">
    '************************************************************************************
    Option Explicit
     Function Executer(StrCmd)
     Dim ws,MyCmd,Resultat
     Set ws = CreateObject("wscript.Shell")
     MyCmd = "CMD /C " & StrCmd & " "
     Resultat = ws.run(MyCmd,0,True)
     Executer = Resultat
    End Function
    '************************************************************************************
    Sub window_onload()
     CenterWindow 400,320
    End Sub
    '************************************************************************************
    Sub CenterWindow(x,y)
     Dim iLeft,itop
     window.resizeTo x,y
     iLeft = window.screen.availWidth/2 - x/2
     itop = window.screen.availHeight/2 - y/2
     window.moveTo ileft,itop
    End Sub
    '************************************************************************************
    </script>
    </head>
    <p>Links :</p>
    <ol>
    <li><a href="#" onClick="Call Executer('Start C:\ScriptExe.exe')">EXE test</a></li>
    <li><a href="#" onClick="Call Executer('Start C:\Tools\Bats\menu.bat')">Bat test</a></li>
    <li><a href="#" onClick="Call Executer('Start chrome.exe www.google.com chrome --app=https://www.google.com/')">Chrome App Test</a></li>
    </ol>
    <BODY>
    
    </body>
    </html>

    The problem with the script, is that I need to use:

    <meta http-equiv="X-UA-Compatible" content="IE=9">

    My existing code only works with IE=9 and breaks alot of things like jquery, if i dont have that tag..

    And If I add the tag to the sample above, it breaks and show me this error when I run the HTA:

    An error has occured in the script on this page. Line: 46 Char: 31 Error: Expected ";" Code: 0

    So looks like something breaks, with this linie and char 31 is: Call Executer

    <li><a href="#" onClick="Call Executer('Start C:\ScriptExe.exe')">EXE test</a></li>

    I have no prior experience with hta, vbs and only a little java.. So I have been using whatever scripts I'm able to find to build this.

    Can anyone tell me, why this don't work with IE=9 content tag? Or perhaps know a better way of doing this?



    Thursday, October 10, 2019 9:38 AM