2

I'm 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..

Right now I'm using this script:

<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 I need to ALT+TAB to switch to them..

I have 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">

And If I add it 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>

If I don't use IE=9 on my HTA program launcher app, I get lots of error with the jquery that I use.

I have no prior experience with hta, vbs and only a little java.. So I have to use whatever scripts I can find.

Can anyone tell me, why this don't work with IE=9 content tag?

Xenosis
  • 87
  • 1
  • 7
  • Did you tried with `IE=8 or IE=10 or IE=Edge` ? And where is the Jquery i didn't see it ? Can you edit and post the whole code with the Jquery ? – Hackoo Oct 07 '19 at 12:25
  • Yes, I have tried other IE versions.. The Jquery stuff is only on my main launcher HTA and not the samples in the topic.. My launcher HTA is to big and complex to share the code here.. But it should not matter, if I just can get the script I post to work with IE=9 then there should be no problem copying the code into my launcher HTA... – Xenosis Oct 08 '19 at 12:03

1 Answers1

2

Please refer to the following sample code to launch app using HTA:

<html>
<head>
    <title>Application Executer</title>
    <HTA:APPLICATION ID="oMyApp" 
        APPLICATIONNAME="Application Executer" 
        BORDER="no"
        CAPTION="no"
        SHOWINTASKBAR="yes"
        SINGLEINSTANCE="yes"
        SYSMENU="yes"
        SCROLL="no"
        WINDOWSTATE="normal">
    <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>

More detail information, your could check How to execute a Local File using HTML Application?

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • Thank for the reply.. I hope there is a better way to do this.. If I need to open multiple programs on the HTA file, the script is needed to be added multiple times.. Also would like to avoid using forward slash.. This complicates things, when you can't just copy the adresse windows uses to a exe file.. So I would prefer finding a fix for the script i post in topic if possible. – Xenosis Oct 08 '19 at 12:13
  • Just use this answer but extend slightly to accept a parameter in RunFile. – bosscube Nov 03 '19 at 14:41