简体   繁体   English

是否可以在 HTML 中的“onclick”上运行 .exe 或 .bat 文件

[英]Is it possible to run an .exe or .bat file on 'onclick' in HTML

Is it possible to run bat/executable file using html5 button event?是否可以使用 html5 按钮事件运行 bat/可执行文件? In IE its achievable using Shell object if I am not wrong.如果我没有错的话,在 IE 中它可以使用 Shell 对象实现。

No, that would be a huge security breach.不,这将是一个巨大的安全漏洞。 Imagine if someone could run想象一下如果有人能跑

format c:

whenever you visted their website.每当您访问他们的网站时。

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.我想要在我们的网络上设置 HTML 页面,这样我就不必导航到各种文件夹来安装或升级我们的应用程序。 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:所以我所做的是在我们每个人都可以访问的“共享”驱动器上设置一个 .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.我更喜欢直接启动 EXE,但这是不可能的,但 .bat 文件允许我解决这个问题。 Wish it worked in FF or Chrome, but only IE.希望它适用于 FF 或 Chrome,但仅限于 IE。

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”

You can do it on Internet explorer with OCX component and on chrome browser using a chrome extension chrome document in 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

You can not run/execute an .exe file that is in the users local machine or through a site.您不能运行/执行位于用户本地计算机或通过站点的 .exe 文件。 The user must first download the exe file and then run the executable file.用户必须先下载exe文件,然后运行可执行文件。
So there is no possible way所以没有办法

The following code works only when the EXE is Present in the User's Machine.以下代码仅在用户机器中存在 EXE 时才有效。

<a href = "C:\\folder_name\\program.exe">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM