js 从浏览器调用本地exe程序(包括IE和谷歌)(转载)
IE浏览器调用本地exe
(谷歌浏览器不支持ActiveXObject
方法,所以这个方法只能在IE浏览器上使用)
function Run() {
var strPath = "E:\\Electron练习\\test1\\out\\test1-win32-x64\\test1.exe";
try {
var objShell = new ActiveXObject("wscript.shell");
objShell.Run(strPath);
}
catch (e) {
alert('找不到文件"' + strPath + '"(或它的组件之一)。请确定路径和文件名是否正确,而且所需的库文件均可用。')
}
}
注意:每个文件夹后面的\
要再加一个\
例如:
原本的exe路径是E:\Electron练习\test1\out\test1-win32-x64\test1.exe
修改之后的路径为:E:\\Electron练习\\test1\\out\\test1-win32-x64\\test1.exe
谷歌浏览器调用本地exe(IE也通用)
1.使用记事本(或其他文本编辑器)创建一个protocal.reg文件,并写入以下内容
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Webshell]
@="URL:Webshell Protocol Handler"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\Webshell\DefaultIcon]
@="E:\\Electron练习\\test1\\out\\test1-win32-x64\\test1.exe"
[HKEY_CLASSES_ROOT\Webshell\shell]
[HKEY_CLASSES_ROOT\Webshell\shell\open]
[HKEY_CLASSES_ROOT\Webshell\shell\open\command]
@="\"E:\\Electron练习\\test1\\out\\test1-win32-x64\\test1.exe\" \"%1\""
2.修改参数
使用记事本打开文件后,按照下图说明修改相关参数
2.1修改连接名称
修改红框内名称自定义即可,全部使用英文字符(该名称即为调用时的href),共六处
![](http://upload-images.jianshu.io/upload_images/6562364-27fd55e27ca1fd49.png?imageMogr2/auto-orient/strip|imageView2/2/w/827/format/webp)
image.png
2.2修改可执行文件路径
修改红框内可执行文件路径,共两处
需注意:文件路径中使用//
分割
![](http://upload-images.jianshu.io/upload_images/6562364-7df7dec42f174181.png?imageMogr2/auto-orient/strip|imageView2/2/w/843/format/webp)
image.png
3.执行protocal.reg文件
![](http://upload-images.jianshu.io/upload_images/6562364-31ac6e0f58e1d80c.png?imageMogr2/auto-orient/strip|imageView2/2/w/591/format/webp)
image.png
4.创建调用连接
![](http://upload-images.jianshu.io/upload_images/6562364-84892169251ade54.png?imageMogr2/auto-orient/strip|imageView2/2/w/721/format/webp)
image.png
在谷歌浏览器中点击链接弹窗确定却没有反应,没有打开exe
![](http://upload-images.jianshu.io/upload_images/6562364-cd3038eaf3276b60.png?imageMogr2/auto-orient/strip|imageView2/2/w/496/format/webp)
image.png
查找原因发现:
在注册表编辑器中找个刚刚创建的注册表,发现路径有乱码,因为路径中有中文,在这里就显示了乱码
手动修改路径乱码为正确的中文,共两处
![](http://upload-images.jianshu.io/upload_images/6562364-dc3a08d710704745.png?imageMogr2/auto-orient/strip|imageView2/2/w/902/format/webp)
image.png
![](http://upload-images.jianshu.io/upload_images/6562364-3565b7adfb78efa4.png?imageMogr2/auto-orient/strip|imageView2/2/w/866/format/webp)
image.png
再次点击谷歌浏览器中的链接就能成功打开exe了
![](http://upload-images.jianshu.io/upload_images/6562364-fd97a72fdb30c7db.png?imageMogr2/auto-orient/strip|imageView2/2/w/503/format/webp)
image.png
作者:李大鱼_
链接:https://www.jianshu.com/p/69c9bf5a5b76
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
qq:505645074