栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

场景

JS中调用本地exe程序:

JS中调用本地exe程序_BADAO_LIUMANG_QIZHI的博客-CSDN博客

在上面的基础上怎样在js中调用本地winform程序并且传递参数。

注:

博客:
BADAO_LIUMANG_QIZHI的博客_霸道流氓气质_CSDN博客-C#,架构之路,SpringBoot领域博主
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、新建或者修改上面的myprotocol.reg注册表文件,在shellopencommand下的

exe路径中添加参数占位符%1

[HKEY_CLASSES_ROOTmyprotocolshellopencommand]
@=""D:\test\UrlProcotolDemo.exe"%1"

完整.reg文件

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTmyprotocol]
@="myprotocol Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOTmyprotocolDefaultIcon]
@="D:\test\UrlProcotolDemo.exe"

[HKEY_CLASSES_ROOTmyprotocolshell]
@=""

[HKEY_CLASSES_ROOTmyprotocolshellopen]
@=""

[HKEY_CLASSES_ROOTmyprotocolshellopencommand]
@=""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文件

​



    



    
        执行可执行文件
    




​

在调用时传递参数badao

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/762901.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号