Windows下浏览器内调起本机应用程序

 本教程使用的方法是自定义协议。在windows下在浏览器内使用自定义协议调起应用程序需要先在注册表内填入相应的值。

首先,导入注册表值(记得改exe文件路径):

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\test]
@="URL:test Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\test\DefaultIcon]
@="C:\\Users\\Administrator\\Desktop\\projects\\manga\\backend\\WebApplication1\\WebApplication1\\bin\\Debug\\net8.0\\WebApplication1.exe,1"
[HKEY_CLASSES_ROOT\test\shell]
[HKEY_CLASSES_ROOT\test\shell\open]
[HKEY_CLASSES_ROOT\test\shell\open\command]
@="C:\\Users\\Administrator\\Desktop\\projects\\manga\\backend\\WebApplication1\\WebApplication1\\bin\\Debug\\net8.0\\WebApplication1.exe \"%1\"" 

 

注意:

方括号内代表的是注册表的路径。HKEY_CLASSES_ROOT\test中的test就是自定义协议的名字,这个名字决定了之后html里的链接该怎么写。

@代表的是路径的默认值。

在注册表内,路径记得用“\\”而不是“\”。

 

这样我们就注册了一个名为“test”的自定义协议。

接下来我们编写一个html文件:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Document</title>
</head>
<body>
  <a href="test:haha">test</a>
</body>
</html>

在浏览器中打开html文件,点击test链接,就可以调起本机应用程序了。

在本机应用程序里应该可以接收到一个test:haha的字符串参数。

参考:Registering an Application to a URI Scheme (Windows) | Microsoft Learn

posted on 2024-01-03 17:33  axel10  阅读(44)  评论(0编辑  收藏  举报