当前位置:网站首页>URL Protocol web page to open the application

URL Protocol web page to open the application

2022-08-09 22:07:00 Calm Nine

URL Protocol

Introduction

Sometimes when developing web pages, you will encounter a function that needs to open a computer-specific program. At this time, you need to use URL Protocol.

The general idea is to first register a custom URL Protocol for the application, and then use the URL Protocol to implement the web page to call the application.

1, add registry

Customize a registry file, similar to Protocol.reg, add the following

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\MyWinform]@="URL:MyWinform Protocol Handler""URL Protocol"=""[HKEY_CLASSES_ROOT\MyWinform\DefaultIcon]@="F:\\AllProjects\\VisualStudio\\TestWinform\\MyWinform\\MyWinform\\bin\\Debug\\MyWinform.exe"[HKEY_CLASSES_ROOT\MyWinform\shell][HKEY_CLASSES_ROOT\MyWinform\shell\open][HKEY_CLASSES_ROOT\MyWinform\shell\open\command]@="\"F:\\AllProjects\\VisualStudio\\TestWinform\\MyWinform\\MyWinform\\bin\\Debug\\MyWinform.exe\" \"%1\""

"MyWinform" in the file is my custom program name, which can be changed to my own application name. Note that the path is double slashes.

2. Writing web pages

Write a simple web page here, which is mainly a hyperlink. The "MyWinform" at the beginning is the user-defined program name, and parameters can be passed later.

Click me to try it

Effects

insert image description here

3. Parameter reception

Here only describes how to accept parameters under Winform, others can study by themselves.

 /// /// The main entry point for the application./// [STAThread]static void Main(string[] args){string inputArgs = string.Join(",", args);if (AnotherAppIsRunning()){MessageBox.Show("A program is already running: " + inputArgs);}else{MessageBox.Show(inputArgs);Console.WriteLine(inputArgs);Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new Form1());Console.WriteLine("The game is officially started!!!!");}}

Rendering

insert image description here

Summary

There are also some ways to add registry in C# script, but it requires administrator privileges. If necessary, you can learn about the RegistryKey class.

原网站

版权声明
本文为[Calm Nine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091906013338.html