Open programs from HTA application

萝らか妹 提交于 2021-02-19 06:00:19

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/58269027/open-programs-from-hta-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!