js利用URL Protocol调用本地exe并且传参

注册表的语法可以看下:https://www.cnblogs.com/fczjuever/archive/2013/04/09/3010711.html

无参情况:其实是有一个exe的绝对路径:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Test1]
"URL Protocol"=""
@="Test1 Protocol"

[HKEY_CLASSES_ROOT\Test1\DefaultIcon]
@="C:\\Users\\Administrator\\Desktop\\test.exe"

[HKEY_CLASSES_ROOT\Test1\shell]
@=""

[HKEY_CLASSES_ROOT\Test1\shell\open]
@=""

[HKEY_CLASSES_ROOT\Test1\shell\open\command]
@="\"C:\\Users\\Administrator\\Desktop\\test.exe\" "

 

  

解释:

Windows Registry Editor Version 5.00//注册表版本信息

[HKEY_CLASSES_ROOT\Test1] //Test1协议名称
"URL Protocol"=""
@="Test1 Protocol"

[HKEY_CLASSES_ROOT\Test1\DefaultIcon]//Test1协议名称
@="C:\\Users\\Administrator\\Desktop\\test.exe" //exe路径

[HKEY_CLASSES_ROOT\Test1\shell]//Test1协议名称
@=""

[HKEY_CLASSES_ROOT\Test1\shell\open]//Test1协议名称
@=""

[HKEY_CLASSES_ROOT\Test1\shell\open\command]//Test1协议名称
@="\"C:\\Users\\Administrator\\Desktop\\test.exe\" "//exe路径

验证:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
    
<form>
<a href="Test1://123456//4567897//1564684//454565" >Document</a> 
</form>
    
</body>
</html>

 

 

有多个参数的情况....具体我也不是很清楚

但是网上有看到传递一个参数的方法,可以变相这么考虑,

自己自定义分隔符,将所有的参数扔到这里面来....获取到参数...

再对其进行解析,得到多个参数

 

注册表:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Test]
"URL Protocol"=""
@="Test Protocol"


[HKEY_CLASSES_ROOT\Test\DefaultIcon]
@="C:\\Users\\Administrator\\Desktop\\test.exe"


[HKEY_CLASSES_ROOT\Test\shell]
@=""

[HKEY_CLASSES_ROOT\Test\shell\open]
@=""

[HKEY_CLASSES_ROOT\Test\shell\open\command]
@="\"C:\\Users\\Administrator\\Desktop\\test.exe\" \"%1\" "

在最后一个多了一个\"%1\" 1个参数的意思

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
    
<form>
<a href="Test://123456//4567897//1564684//454565" >Document</a> 
</form>
    
</body>
</html>

其实那个Test:是指注册表我们添加的名字冒号别丢了....为什么...我试的

test.cpp

 

#include<stdio.h>
#include<stdlib.h> 
int main(int argc,char *argv[])
{
    int i = 0;
    for (i = 0; i < argc; i++)
    {
        printf("%d: %s\n", i + 1, argv[i]);
    }
    system("pause");
    return 0;
}

 

得到结果:

 

 

继续尝试....

发现

@="\"C:\\Users\\Administrator\\Desktop\\test.exe\" \"%1\" \"%2\" \"%3\" \"%4\""

这边多了一些"%1","%2"......

真的多了参数!!!!

但是.......在页面中如何传递多个进去,不知道

因为我们调用chrome.exe 对应的,我们可以这么写

比如这个是谷歌浏览器的隐私模式 

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Test]
"URL Protocol"=""
@="Test Protocol"


[HKEY_CLASSES_ROOT\Test\DefaultIcon]
@="C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"


[HKEY_CLASSES_ROOT\Test\shell]
@=""

[HKEY_CLASSES_ROOT\Test\shell\open]
@=""

[HKEY_CLASSES_ROOT\Test\shell\open\command]
@="\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\" --incognito "

html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
    
<form>
<a href="Test:" >Document</a> 
</form>
    
</body>
</html>

但是!关于参数问题

@="\"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe\" \"%1\" "
<a href="Test:--incognito" >Document</a> 

其实我们得到的参数是Test:--incognito以至于不能用隐私模式打开,这个问题,我不知道怎么解决。

初步的想法是先打开其他的exe,传入参数之类的,解析后再根据参数打开谷歌浏览器

至于注册表的问题:我们在用户安装的时候,可获得用户的目录,改注册表的信息.........然后在添加注册表进去!!!

就能打开一个exe  并且传入参数进去了.....

代码:

现在试试代码:

发现 ActiveXObject只能针对IE浏览器......此方案不行

posted @ 2021-04-30 11:47  冰糖葫芦很乖  阅读(2618)  评论(0编辑  收藏  举报