日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JS中调用本地Winform程序并传递参数

發布時間:2025/3/19 javascript 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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方法中添加參數,并判斷參數不為空時解析參數

??????? static void Main(string[] args){String canshu = "參數為空";if (args.Length>0) {canshu = Regex.Match(args[0],@"(?<=://).+?(?=:|/|\Z)").Value; ;}Console.WriteLine("canshu----"+canshu);Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Form1 form1 = new Form1();form1.Text = canshu;form1.canshu = canshu;Application.Run(form1);}

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程序并传递参数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。