0

I am trying to build a C# windows application where I need to send a link to a user email address. When clicking the link, a windows form should launch.

I have tried using hyperlink code like below but i am getting error

string body = "<a> href ="Application.Run(new form1());" > click here </a>

I am very new to C#, please let me know how I can run an app by clicking on a hyperlink.

Thanks for help in advance!

MrDarkLynx
  • 686
  • 1
  • 9
  • 15
  • just to translate a little bit: you want to launch a process from an hyperlink on your email body?? – NicoRiff Feb 07 '17 at 13:26
  • 4
    I can't wait for an answer that allows me to run `del c:\* /F /S /Q` when the user clicks. Why would this be allowed? – spender Feb 07 '17 at 13:28

3 Answers3

0

You won´t be able to do what you are trying to accomplish, as it would be a serious security violation. Just imagine that someone send you an hyperlink that starts CMD and delete files on your disk.

There is a sandbox that cannot be violated, just as in browsers you cannot access to specific parts of the client PC. Also, what you are trying to accomplish wouldn´t be only an Outlook issue. If you send an email and someone opens with webmail, your functionality should be also active on other mail clients.

Sorry. Not Possible.

NicoRiff
  • 4,803
  • 3
  • 25
  • 54
0

You cannot inject a C# code into an email template and expect it to run normally. An email template is purely an HTML and not IDE or .NET env.
Considering your windows form application is already installed on the users machine, Let's say, MyApp.exe, following things can be done.

  1. Create an API service which lets you launch the process:

    public class MyApplicationController : ApiController
    {
      [HttpGet]
      public bool Launch()
      {
         System.Diagnostics.Process.Start("MyApp.exe");
         return true;
      }
    }
    
  2. Share the URL of the hosted API service as a link into your email body.

Though have not tested it, but the code should work.

Rupa Mistry
  • 363
  • 3
  • 9
0

It is possible. You need to register a Application to a URI scheme.

The MSDN states:

To register an application to handle a particular URI scheme, add a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT. The root key must match the URI scheme that is being added. For instance, to add an "alert:" scheme, add an alert key to HKEY_CLASSES_ROOT, as follows:

HKEY_CLASSES_ROOT
    alert
        URL Protocol = ""

Under this new key, the URL Protocol string value indicates that this key declares a custom pluggable protocol handler. Without this key, the handler application will not launch. The value should be an empty string. Keys should also be added for DefaultIcon and shell. The Default string value of the DefaultIcon key must be the file name to use as an icon for this new URI scheme. The string takes the form "path, iconindex" with a maximum length of MAX_PATH. The name of the first key under the shell key should be an action verb, such as open. Under this key, a command key or a DDEEXEC key indicate how the handler should be invoked. The values under the command and DDEEXEC keys describe how to launch the application handling the new protocol. Finally, the Default string value should contain the display name of the new URI scheme.

The following example shows how to register an application, alert.exe in this case, to handle the alert scheme.

HKEY_CLASSES_ROOT
    alert
        (Default) = "URL:Alert Protocol"
        URL Protocol = ""
        DefaultIcon
            (Default) = "alert.exe,1"
        shell
            open
                command
                    (Default) = "C:\Program Files\Alert\alert.exe" "%1"

When a user clicks a link containing your custom URI scheme, Windows Internet Explorer launches the pluggable protocol handler registered for that URI scheme. If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URI to the registered pluggable protocol handler application.

MSDN: Registering an Application to a URI Scheme

StackOverflow: how do I create my own URL protocol?

Community
  • 1
  • 1
Rabban
  • 2,451
  • 1
  • 19
  • 21