从HTA应用程序打开程序 [英] Open programs from HTA application

查看:94
本文介绍了从HTA应用程序打开程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个HTA应用程序,该应用程序可以在计算机上本地打开程序(exe,bat等.).

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

这将在用户无法访问台式机等的Kiosk PC上使用.

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>

这是我的链接的外观:

<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>

此脚本的问题在于,我从启动器HTA打开的某些程序位于全屏运行的HTA应用程序的下方.因此,我需要使用ALT + TAB切换到它们..

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..

我一直在寻找另一个脚本,并找到了这个HTA示例,它看起来是一种更好的实现方式:

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

如果我将其添加到上面的示例中,它会中断并在运行HTA时向我显示此错误:

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

此页面上的脚本中发生了错误.行:46字符:31错误:预期为;"代码:0

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

所以看起来有些破事了,这条直线和char 31是:调用执行程序

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>

如果我在HTA程序启动器应用程序上未使用IE = 9,则使用的jquery会出现很多错误.

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

我以前没有使用过HTA,VBS和Java的经验.因此,我必须使用可以找到的任何脚本.

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

谁能告诉我,为什么这不适用于IE = 9内容标签?

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

推荐答案

请参考以下示例代码以使用HTA启动应用程序:

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>

更多详细信息,您可以检查如何执行本地文件使用HTML应用程序?

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

这篇关于从HTA应用程序打开程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆