javascript
JS中调用本地Winform程序并传递参数
場(chǎng)景
JS中調(diào)用本地exe程序:
JS中調(diào)用本地exe程序_BADAO_LIUMANG_QIZHI的博客-CSDN博客
在上面的基礎(chǔ)上怎樣在js中調(diào)用本地winform程序并且傳遞參數(shù)。
注:
博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質(zhì)_CSDN博客-C#,架構(gòu)之路,SpringBoot領(lǐng)域博主
關(guān)注公眾號(hào)
霸道的程序猿
獲取編程相關(guān)電子書(shū)、教程推送與免費(fèi)下載。
實(shí)現(xiàn)
1、新建或者修改上面的myprotocol.reg注冊(cè)表文件,在shell\open\command下的
exe路徑中添加參數(shù)占位符%1
[HKEY_CLASSES_ROOT\myprotocol\shell\open\command] @="\"D:\\test\\UrlProcotolDemo.exe\"%1"完整.reg文件
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\myprotocol] @="myprotocol Protocol" "URL Protocol"=""[HKEY_CLASSES_ROOT\myprotocol\DefaultIcon] @="D:\\test\\UrlProcotolDemo.exe"[HKEY_CLASSES_ROOT\myprotocol\shell] @=""[HKEY_CLASSES_ROOT\myprotocol\shell\open] @=""[HKEY_CLASSES_ROOT\myprotocol\shell\open\command] @="\"D:\\test\\UrlProcotolDemo.exe\"%1"然后雙擊運(yùn)行該reg文件,重新注冊(cè)注冊(cè)表。
2、新建winform程序,頁(yè)面添加一個(gè)label
主窗體中添加Public變量,用來(lái)接收傳遞的參數(shù),并在窗體load方法中將變量賦值給label
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;namespace UrlProcotolDemo {public partial class Form1 : Form{public String canshu = String.Empty;public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){label1.Text = canshu;}} }
修改Program.cs,Main方法中添加參數(shù),并判斷參數(shù)不為空時(shí)解析參數(shù)
3、編譯生成winfrom的exe項(xiàng)目,將其放在上面注冊(cè)表文件對(duì)應(yīng)的路徑下
4、新建或者修改html文件
? <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <div><a href="myprotocol://badao">執(zhí)行可執(zhí)行文件</a> </div> </body> </html>?在調(diào)用時(shí)傳遞參數(shù)badao
總結(jié)
以上是生活随笔為你收集整理的JS中调用本地Winform程序并传递参数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JS中调用本地exe程序
- 下一篇: Vue+Openlayers+HIKVS