瀏覽器啟動(dòng)windows本地程序

公司打印插件有個(gè)需求,需要瀏覽器點(diǎn)擊去啟動(dòng)那個(gè)插件程序,網(wǎng)上搜了下,解決的思路是通過URL Protocol去調(diào)起桌面程序
1.需要在c#程序中添加注冊(cè)表,或者手動(dòng)添加注冊(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容