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

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

 



这篇关于网页通过注册表调用本地程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程