是否可以在 HTML 中的“onclick”上运行 .exe 或 .bat 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18980957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to run an .exe or .bat file on 'onclick' in HTML
提问by VSr
Is it possible to run bat/executable file using html5 button event? In IE its achievable using Shell object if I am not wrong.
是否可以使用 html5 按钮事件运行 bat/可执行文件?如果我没有错的话,在 IE 中它可以使用 Shell 对象实现。
采纳答案by Chuff
Here's what I did. I wanted a HTML page setup on our network so I wouldn't have to navigate to various folders to install or upgrade our apps. So what I did was setup a .bat file on our "shared" drive that everyone has access to, in that .bat file I had this code:
这就是我所做的。我想要在我们的网络上设置 HTML 页面,这样我就不必导航到各种文件夹来安装或升级我们的应用程序。所以我所做的是在我们每个人都可以访问的“共享”驱动器上设置一个 .bat 文件,在该 .bat 文件中我有以下代码:
start /d "\server\Software\" setup.exe
The HTML code was:
HTML代码是:
<input type="button" value="Launch Installer" onclick="window.open('file:///S:Test/Test.bat')" />
(make sure your slashes are correct, I had them the other way and it didn't work)
(确保你的斜线是正确的,我用另一种方式,它没有用)
I preferred to launch the EXE directly but that wasn't possible, but the .bat file allowed me around that. Wish it worked in FF or Chrome, but only IE.
我更喜欢直接启动 EXE,但这是不可能的,但 .bat 文件允许我解决这个问题。希望它适用于 FF 或 Chrome,但仅限于 IE。
回答by Doorknob
No, that would be a hugesecurity breach. Imagine if someone could run
不,这将是一个巨大的安全漏洞。想象一下如果有人能跑
format c:
whenever you visted their website.
每当您访问他们的网站时。
回答by user247702
It is possible when the page itself is opened via a file:///
path.
当页面本身通过file:///
路径打开时是可能的。
<button onclick="window.open('file:///C:/Windows/notepad.exe')">
Launch notepad
</button>
However, the moment you put it on a webserver (even if you access it via http://localhost/
), you will get an error:
然而,当你把它放在网络服务器上时(即使你通过 访问它http://localhost/
),你会得到一个错误:
Error: Access to 'file:///C:/Windows/notepad.exe' from script denied
错误:拒绝从脚本访问“file:///C:/Windows/notepad.exe”
回答by Stefan Kanev
You can do it on Internet explorer with OCX component and on chrome browser using a chrome extension chrome documentin any case need additional settings on the client system!
您可以在带有 OCX 组件的 Internet Explorer 和使用 chrome 扩展chrome 文档的chrome 浏览器上执行此操作, 在任何情况下都需要在客户端系统上进行其他设置!
Important part of chrome extension source:
chrome扩展源的重要部分:
var port = chrome.runtime.connectNative("your.app.id");
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
port.postMessage("send some data to STDIO");
permission file:
权限文件:
{
"name": "your.app.id",
"description": "Name of your extension",
"path": "myapp.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://IDOFYOUREXTENSION_lokldaeplkmh/"
]
}
and windows registry settings:
和 Windows 注册表设置:
HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\your.app.id
REG_EXPAND_SZ : c:\permissionsettings.json
回答by coolprarun
You can not run/execute an .exe file that is in the users local machine or through a site. The user must first download the exe file and then run the executable file.
So there is no possible way
您不能运行/执行位于用户本地计算机或通过站点的 .exe 文件。用户必须先下载exe文件,然后运行可执行文件。
所以没有办法
The following code works only when the EXE is Present in the User's Machine.
以下代码仅在用户机器中存在 EXE 时才有效。
<a href = "C:\folder_name\program.exe">
<a href = "C:\folder_name\program.exe">