C# 网页通过注册表调用本地程序
要调用的本地程序地址
E:\\PSWebPrint.exe
编写txt文件,内容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\PS.PrintShipLabel]
"URL Protocol"="E:\\PSWebPrint.exe"
@="PS.PrintShipLabel"
[HKEY_CLASSES_ROOT\PS.PrintShipLabel\DefaultIcon]
@="E:\\A\\PSWebPrint\\PSWebPrint\\bin\\Debug\\PSWebPrint.exe,1"
[HKEY_CLASSES_ROOT\PS.PrintShipLabel\shell]
[HKEY_CLASSES_ROOT\PS.PrintShipLabel\shell\open]
[HKEY_CLASSES_ROOT\PS.PrintShipLabel\shell\open\command]
@="\"E:\\PSWebPrint.exe\" \"%1\""
注册表名称为PS.PrintShipLabel,将以上的内容保存到文本里面,另存为PS.PrintShipLabel.reg(名字随意,后缀为.reg即可),
其中最后的“ %1 ”表示应用程序接收参数。。。@表示默认值
也可以编写用程序创建注册表
#region 创建注册表 public void createRegistry() { string exePath = Application.ExecutablePath;//调用的程序地址 PdfPrint.TryLoadNativeLibrary(System.Windows.Forms.Application.StartupPath); exePath = exePath.Replace("\\", "\\\\"); RegistryKey hklm = Registry.ClassesRoot; RegistryKey key = hklm.CreateSubKey(@"PS.PrintShipLabel"); key.SetValue("URL Protocol", exePath); RegistryKey key2 = key.CreateSubKey(@"DefaultIcon"); key2.SetValue("", exePath); RegistryKey key3 = key.CreateSubKey(@"shell"); RegistryKey key4 = key3.CreateSubKey(@"open"); RegistryKey key5 = key4.CreateSubKey(@"command"); key5.SetValue("", exePath + " %1"); hklm.Close(); key.Close(); } #endregion
前端js调用
function print() { window.location.href = 'PS.PrintShipLabel://12331233; }
PS.PrintShipLabel为注册表名称
PS.PrintShipLabel://后为要传递的参数
后台接收处理注册表传递的参数
//获取参数 string parameter = ""; if (args.Length > 0) { parameter = Regex.Match(args[0], @"(?<=://).+?(?=:|/|\Z)").Value; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)