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



