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瀏覽器......此方案不行


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM