【发布时间】:2019-10-07 11:52:18
【问题描述】:
我正在尝试创建一个 HTA 应用程序,它可以在计算机上本地打开程序(exe、bat 等)。
这将用于 Kiosk PC,用户无权访问桌面等。
但是有一些问题,找到一个有效的脚本..
现在我正在使用这个脚本:
<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 切换到它们。
我一直在寻找另一个脚本,并找到了这个 HTA 示例,这看起来是一种更好的方法:
<!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>
脚本的问题,是我需要使用:
<meta http-equiv="X-UA-Compatible" content="IE=9">
如果我将它添加到上面的示例中,它会在我运行 HTA 时中断并显示此错误:
此页面上的脚本出现错误。行:46 字符:31 错误:应为“;”代码:0
所以看起来有些东西坏了,这个 linie 和 char 31 是:调用执行器
<li><a href="#" onClick="Call Executer('Start C:\ScriptExe.exe')">EXE test</a></li>
如果我不在我的 HTA 程序启动器应用上使用 IE=9,我使用的 jquery 会出现很多错误。
我之前没有使用 hta、vbs 的经验,只有一点 java.. 所以我必须使用我能找到的任何脚本。
谁能告诉我,为什么这不适用于 IE=9 内容标签?
【问题讨论】:
-
你试过
IE=8 or IE=10 or IE=Edge吗?我没看到的 Jquery 在哪里?你能用 Jquery 编辑和发布整个代码吗? -
是的,我尝试过其他 IE 版本。。Jquery 的东西只在我的主启动器 HTA 上,而不是主题中的示例。。我的启动器 HTA 太大而复杂,无法在此处共享代码..但没关系,如果我可以让我发布的脚本与 IE=9 一起工作,那么将代码复制到我的启动器 HTA 中应该没有问题......
标签: javascript vbscript internet-explorer-9 hta