ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

网页通过注册表调用本地程序

2022-08-25 09:00:39  阅读:155  来源: 互联网

标签:PS 调用 网页 RegistryKey PrintShipLabel 注册表 exePath PSWebPrint


要调用的本地程序地址

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;
}

 

标签:PS,调用,网页,RegistryKey,PrintShipLabel,注册表,exePath,PSWebPrint
来源: https://www.cnblogs.com/8999zzz/p/16623028.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有