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

VSr*_*VSr 35 javascript html5 dom

是否可以使用html5按钮事件运行bat/executable文件?在IE中,如果我没有错,可以使用Shell对象实现.

Doo*_*nob 33

不,这将是一个巨大的安全漏洞.想象一下,如果有人可以跑

format c:
Run Code Online (Sandbox Code Playgroud)

每当你访问他们的网站.

  • 这是正确的,但我同时笑......:D (2认同)

小智 21

这就是我做的.我想在我们的网络上设置HTML页面,因此我不必导航到各种文件夹来安装或升级我们的应用程序.所以我所做的是在我们的"共享"驱动器上设置一个.bat文件,每个人都可以访问,在.bat文件中我有这个代码:

start /d "\\server\Software\" setup.exe
Run Code Online (Sandbox Code Playgroud)

HTML代码是:

<input type="button" value="Launch Installer" onclick="window.open('file:///S:Test/Test.bat')" />
Run Code Online (Sandbox Code Playgroud)

(确保你的斜线是正确的,我用另一种方式,但它不起作用)

我更喜欢直接启动EXE,但这是不可能的,但.bat文件允许我解决这个问题.希望它在FF或Chrome中有效,但只有IE.


use*_*702 18

通过file:///路径打开页面本身是可能的.

<button onclick="window.open('file:///C:/Windows/notepad.exe')">
    Launch notepad
</button>
Run Code Online (Sandbox Code Playgroud)

但是,当您将其放在网络服务器上时(即使您通过它访问它http://localhost/),您将收到错误:

错误:从拒绝的脚本访问'file:/// C:/Windows/notepad.exe'

  • 这允许"下载"notepad.exe,而不是运行它.Firefox 31,Windows 7 (3认同)
  • @Stijn 在这种情况下执行的文件是您刚刚“下载”的文件,而不是原始文件。所以在大多数情况下它不起作用 - 它不允许您运行计算机上已安装的程序。 (2认同)

小智 6

您可以在带有 OCX 组件的 Internet Explorer 上执行此操作,也可以在使用 chrome 扩展 chrome 文档的chrome 浏览器上执行此 操作,无论如何都需要在客户端系统上进行其他设置!

chrome扩展源码的重要部分:

var port = chrome.runtime.connectNative("your.app.id"); 
      port.onMessage.addListener(onNativeMessage); 
      port.onDisconnect.addListener(onDisconnected);
      port.postMessage("send some data to STDIO");
Run Code Online (Sandbox Code Playgroud)

权限文件:

{
      "name": "your.app.id",
      "description": "Name of your extension",
      "path": "myapp.exe",
      "type": "stdio",
      "allowed_origins": [
            "chrome-extension://IDOFYOUREXTENSION_lokldaeplkmh/"
      ]
}
Run Code Online (Sandbox Code Playgroud)

和 Windows 注册表设置:

HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\your.app.id
REG_EXPAND_SZ : c:\permissionsettings.json
Run Code Online (Sandbox Code Playgroud)