當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS中调用本地Winform程序并传递参数
生活随笔
收集整理的這篇文章主要介紹了
JS中调用本地Winform程序并传递参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
JS中調用本地exe程序:
JS中調用本地exe程序_BADAO_LIUMANG_QIZHI的博客-CSDN博客
在上面的基礎上怎樣在js中調用本地winform程序并且傳遞參數。
注:
博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓氣質_CSDN博客-C#,架構之路,SpringBoot領域博主
關注公眾號
霸道的程序猿
獲取編程相關電子書、教程推送與免費下載。
實現
1、新建或者修改上面的myprotocol.reg注冊表文件,在shell\open\command下的
exe路徑中添加參數占位符%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"然后雙擊運行該reg文件,重新注冊注冊表。
2、新建winform程序,頁面添加一個label
主窗體中添加Public變量,用來接收傳遞的參數,并在窗體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方法中添加參數,并判斷參數不為空時解析參數
3、編譯生成winfrom的exe項目,將其放在上面注冊表文件對應的路徑下
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">執行可執行文件</a> </div> </body> </html>?在調用時傳遞參數badao
總結
以上是生活随笔為你收集整理的JS中调用本地Winform程序并传递参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS中调用本地exe程序
- 下一篇: Vue+Openlayers+HIKVS