浏览器启动windows本地程序

公司打印插件有个需求,需要浏览器点击去启动那个插件程序,网上搜了下,解决的思路是通过URL Protocol去调起桌面程序
1.需要在c#程序中添加注册表,或者手动添加注册表

static void RegisterMyProtocol(string myAppPath)  //myAppPath = full path to your application
{
      RegistryKey key = Registry.ClassesRoot.OpenSubKey("myApp");  //open myApp protocol's subkey

      if (key == null)  //if the protocol is not registered yet...we register it
      {
          key = Registry.ClassesRoot.CreateSubKey("myApp"); 
          key.SetValue(string.Empty, "URL: myApp Protocol");
          key.SetValue("URL Protocol", string.Empty);

          key = key.CreateSubKey(@"shell\open\command");
          key.SetValue(string.Empty, myAppPath + " " + "%1");  
         //%1 represents the argument - this tells windows to open this program with an argument / parameter
      }

      key.Close();
}

2.在浏览器页面中打开
window.open("myApp://")

参考:
https://codingvision.net/c-register-a-url-protocol
https://medium.com/front-end-weekly/launching-desktop-application-from-browser-using-custom-protocol-c-598c4519c839

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容