要调用的本地程序地址
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;
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/282161.html