网页通过注册表调用本地程序
2022/8/25 14:23:19
本文主要是介绍网页通过注册表调用本地程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
要调用的本地程序地址
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; }
这篇关于网页通过注册表调用本地程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-26敏捷开发:想要快速交付就必须舍弃产品质量?
- 2024-04-26静态代码分析的这些好处,我竟然都不知道?
- 2024-04-26你在测试金字塔的哪一层?(下)
- 2024-04-26快刀斩乱麻,DevOps让代码评审也自动起来
- 2024-04-262024年最好用的10款ER图神器!
- 2024-04-2203-为啥大模型LLM还没能完全替代你?
- 2024-04-2101-大语言模型发展
- 2024-04-17基于SpringWeb MultipartFile文件上传、下载功能
- 2024-04-14个人开发者,Spring Boot 项目如何部署
- 2024-04-14RAG应用开发实战02-相似性检索的关键 - Embedding