Open exe in the web page

Posted by RussW on Tue, 14 May 2019 12:08:09 +0200

                     

Can you open the local exe file on the web page?

Simon said: Yes.

The methods are as follows:

 

1. Define a private protocol that points to the local exe
2. Use this private protocol as a URL on the web page and click on it to open the exe.
3. The URL can also contain parameters that are passed to the exe

1. Define a private protocol
Protocol, http is a well-known example. By typing this in the browser, the browser can understand that it is opening a web page. So, this private agreement is used to open our damn exe.

What is the definition of private agreements? Simply change the registry. Write a script, name the file suffix correctly, double-click, windows can recognize and run, modify the registry.

Example, Notepad open, input script as follows:

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\HYZT]@="URL:HYZT Protocol Handler""URL Protocol"=""[HKEY_CLASSES_ROOT\HYZT\shell][HKEY_CLASSES_ROOT\HYZT\shell\open][HKEY_CLASSES_ROOT\HYZT\shell\open\command]@="E:\\hyzt\\bin\\Debug\\hyzt.exe %1"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

The file is saved as hyzt.reg. Then double-click the file and the registry will be modified. The file can be modified many times and run many times. The new modification covers the original.

In this way, we define a private protocol: hyzt.

2. Include this protocol in the URL
Now, enter hyzt:/// in the address bar of your local browser, and you can turn on the damn exe. IE is OK. In the case of chrome, direct input in browsers sometimes does not work. You can define a bookmark (similar to the collection in IE favorites). Just click on it.

When we learn the http protocol, we come across two nouns: URI and URL. What's the difference between the two?

 

URI, Uniform Resource Locator; URL, Uniform Resource Locator. Simply put, URL = protocol + URI.

For example, www.baidu.com is a URI, while http://www.baidu.com Is a URL.

That is to say, URL s not only indicate the location of resources, but also the method (protocol) of accessing resources. http is a protocol, and our hyzt is also a protocol.

3. Passing parameters to exe in the URL
We can turn on exe with hyzt:// What if you want to pass parameters? It can be similar to purple sauce:

hyzt://1000,chenqu
  • 1

Note that the parameters received by exe are not 1000,chenqu, but complete hyzt://1000,chenqu!

Enclosed exe receive parameters and process:

namespace TackColor{    static class Program    {        /// <summary>        /// The main entry point of the application.        /// </summary>        [STAThread]        static void Main(string[] paras)        {            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Form1(paras));        }    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
namespace TackColor{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        string _UserId = "0";        string _UserName = "";        public Form1(string[] paras) : this()        {            pickupParam(paras);        }        private void Form1_Load(object sender, EventArgs e)        {            MessageBox.Show(String.Format("user ID: {0},User name:{1}",this._UserId,this._UserName));        }        void pickupParam(string[] paras)        {            if(paras == null && paras.Length == 0)            {                return;            }            string p = paras[0];            Regex rx = new Regex(@"hyzt\://(?<p>[^/]+)/?", RegexOptions.Compiled | RegexOptions.IgnoreCase);            Match m = rx.Match(p);            if(m.Success)            {                string[] ps = m.Result("${p}").Split(',');                if(ps.Length > 0)                {                    this._UserId = ps[0];                }                if (ps.Length > 1)                {                    this._UserName = ps[1];                }            }        }    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

4. Combining Private Protocol with Program Installation Package
In the private agreement, the path of the corresponding executable file is clearly indicated:

[HKEY_CLASSES_ROOT\HYZT\shell\open\command]@="C:\\hyzt\\bin\\Debug\\hyzt.exe %1"
  • 1
  • 2

The problem is that the actual situation of each client varies greatly. For example, in this example, some machines do not have C disk at all, and executable files may be installed on D disk. Do you have to change this registry file manually before it runs?
One idea is that this registry modification work is placed in the installation package of the program. Private protocols are written in when users install them.

           

Topics: Programming shell Windows IE