html(Angular) 调用本地安装exe程序

1、写注册表

  新建 .reg文件

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTcreoparametric]
"URL Protocol"=""
@="URL:creoparametric"

[HKEY_CLASSES_ROOTcreoparametricshell]

[HKEY_CLASSES_ROOTcreoparametricshellopen]

[HKEY_CLASSES_ROOTcreoparametricshellopencommand]
@=""D:\PTC\Creo 6.0.5.1\Parametric\bin\parametric.exe" "%1""

  保持并双击执行写入。

2、调用

url = 'creoparametric://'; //无参数
url = 'creoparametric://param1&param2';  //带参数

  可以使用<a [href]="url"> 或者  window.open(url, '_blank', 'noopener'); 等方式调用

3、测试服务端(c#),

  新建窗体程序

    static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args));
        }
    }

  Form

    public partial class Form1 : Form
    {
        string[] args;
        public Form1(string[] args)
        {
            this.args = args;
            InitializeComponent();
            LogHelper.Info("参数个数:" + args.Length.ToString());
            foreach (var a in args)
            {
                LogHelper.Info("参数:" + a);
                this.label1.Text += " " + a;
            }

        }
    }

  按照1和2,新建测试案例注册表:url='aaaamytest://'

<a href="aaaamytest://param1&param2"> 

  进行测试后,日志:

--------2021-04-29 10:23:42,435--------
参数个数:1
--------2021-04-29 10:23:42,443--------
参数:aaaamytest://param1&param2/
原文地址:https://www.cnblogs.com/wskxy/p/14717322.html