整体思路:html引用URL protocol-本地注册表key,key对应某一c#写的exe可执行文件,由exe可执行文件调用cmd,cmd执行jar包。
1、添加注册表:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Print]
"URL Protocol"="d:\\Print\\SupplementPrint.exe"
@="PrintProtocol"
[HKEY_CLASSES_ROOT\Print\DefaultIcon]
@="d:\\Print\\SupplementPrint.exe,1"
[HKEY_CLASSES_ROOT\Print\shell]
[HKEY_CLASSES_ROOT\Print\shell\open]
[HKEY_CLASSES_ROOT\Print\shell\open\command]
@="\"d:\\Print\\SupplementPrint.exe\"\"%1\""
说明:第一行,注册版本信息,无需关注;2,、注册表中key值,html中也需要引用这个key“Print”,3、此key对应的exe文件。4、协议名称。。。
2、编写C#调用cmd.exe,cmd再调用jar包。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Text.RegularExpressions; namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//string fullPath = System.Windows.Forms.Application.ExecutablePath;
//System.Console.WriteLine("Hello world");
//System.Console.WriteLine(fullPath);
//string fileName = System.IO.Path.GetFileName(fullPath);
//string folderPath = fullPath.Substring(,fullPath.Length-fileName.Length);
//string cmd = "start " + folderPath + " jre/bin/javaw - jar " + folderPath + "zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar";
//System.Console.WriteLine(cmd);
RunCmd(cmd);
} private static void RunCmd(string cmd)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//string str = Console.ReadLine();
string str = @"java -jar c:\\Users\\10244896\\Desktop\\print\\zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar" + "&exit";
str = str.Trim().TrimEnd('&');
p.Start();
p.StandardInput.WriteLine(str); p.StandardInput.AutoFlush = true;
//p.StartInfo.Arguments = "java -jar c:\\Users\\10244896\\Desktop\\print\\zte-mes-supplementPrint-javaFX-0.0.1-SNAPSHOT.jar"; p.WaitForExit();
// throw new NotImplementedException();
}
}
}
说明:仅关注runCmd方法即可。
3、编写html
<a href="Print://hello">Print</a>