mercredi 23 janvier 2019

How to call local desktop program (EXE) from a website

I had a question How to execute desktop application on client machine from website to know the solution i spent much time to find the answer actually i found solution in pieces and merge them all to resolve the issue therefore my this post to help others so they can find full solution step by step in one page.

To execute your desktop application from website there are total three steps:

  1. Build your EXE file and place in a folder
  2. Define URL-PROTOCOL on client machine
  3. Redirect user to URL from your website.

let go for the detail of each step:

1. Build you EXE file and place in a folder Install your desktop application build (EXE/dlls files) on client machine let say folder is “C:\MyApplication\” and application name is “My.exe” so full path will become “C:\MyApplication\My.exe”

2. Define URL-PROTOCOL on client machine Define URL-PROTOCOL to do so you need to write some registry entries on client windows machine.

below are the registry entries you may copy and paste in notepad and save file as 'MyRegistryEntries.reg' and execute it on client machine in order to register URL. or else you may enter manually using RUN command => Regedit

[HKEY_CLASSES_ROOT\MyApplication]
@="URL: MyApplication Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\MyApplication\DefaultIcon]
@="\"C:\\MyApplication\\My.exe\""

[HKEY_CLASSES_ROOT\MyApplication\shell]

[HKEY_CLASSES_ROOT\MyApplication\shell\open]

[HKEY_CLASSES_ROOT\MyApplication\shell\open\command]
@="\"C:\\MyApplication\\My.exe\" \"%1\" \"%2\" \"%3\""

from the above registry windows will allow to access your application from your define url protocol, to test on this stage open internet explore and type "MyApplication:1" on url bar or you also may run command in windows Run => MyApplication:1

please note, %1,%2 are arguments you may use in the case EXE require

3. Redirect user to URL on website. now it time to execute your desktop program from the website. so you need to redirect user to defined url (MyApplication:1) so simplest code on ASP.net can be as follows:

protected void btnEXE_Click(object sender,EventArgs e) {
            string _url=" MyApplication:1";
            Response.Redirect(_url);
}

at last, You may control registry entry by different smart ways like you many control within your installation or can set on first execution of your application and so on.

i hope this post will help others




Aucun commentaire:

Enregistrer un commentaire