locked
How to launch an exe on the click of a button in asp.net application. RRS feed

  • Question

  • User-356829294 posted

    Hi,

    I am using ActiveXObjects to launch an exe in my asp.net application, but that is not the most handsome solution that I came across as it is limited to be used in Internet Explorer and soon ActiveXObjects will be obsolete.

    Is there a better way to achieve this(launching exe from an asp.net application) in asp.net application.

    Thanks

    Vinod

    Wednesday, December 27, 2017 3:37 PM

All replies

  • User753101303 posted

    Hi,

    Knowing your exact scenario could help. For example if you have to, you could associate a client side app with a particular file extension. What does this app ?

    Wednesday, December 27, 2017 4:16 PM
  • User-474980206 posted

    there is no better way. browser security has removed this feature. as you suggested this feature will also disappear in future versions of IE.

    if you control the exe code, then a long term solution is to have the exe register a mime-type it responds to. the the web application could download a message of they mimic-type and the browser would open the application.

    note: if this is an internal app, then you should write a launcher application, that registers a mimic-type that users install, and the payload could identify the exe to run.

    Wednesday, December 27, 2017 7:53 PM
  • User-832373396 posted

    Hi vsinghal,

    Sir, I guess that you are looking for this, then it executes the .exe application;

    Simple Working Example:

    class Program {
        static void Main(string[] args) {
    
            Notepad np = new Notepad();
            Thread th = new Thread(new ThreadStart(np.startNPprocess));
            th.Start();
    
            Console.WriteLine("press [enter] to exit");
            Console.ReadLine();
        }
    }
    
    public class Notepad {
    
        public void startNPprocess() {
    
            Process pr = new Process();
            ProcessStartInfo prs = new ProcessStartInfo();
            prs.FileName = @"notepad.exe";
            pr.StartInfo = prs;
            pr.Start();     
    
        }
    }

    With regards, Angelina Jolie

    Thursday, December 28, 2017 6:51 AM
  • User-356829294 posted

    Hi Angelina,

    Thanks for you response.

    This approach suggested by you does not work if the web application is hosted on IIS because app pool does not allow exe to run on the server. I need to run my exe on the client side. So, I need some code which runs the exe on the client side.

    Vinod

    Thursday, December 28, 2017 7:46 AM
  • User-356829294 posted

    Hi,

    Thanks for you response.

    The exe code is in my control as it is a WPF app which is created by my team only. I just want to launch that WPF app exe from a different web application.

    The approach suggested by you looks interesting, I would appreciate if you can share a link where I can study in detail the approach suggested.

    Thanks

    Vinod

    Thursday, December 28, 2017 7:48 AM
  • User-356829294 posted

    Hi,

    Thanks for you response.

    Exact scenarios is, we have created a WPF app and created an exe of the same using ClickOnce. Now, I want to launch this exe from a web application that is based on VB.net.

    Thanks

    Vinod

    Thursday, December 28, 2017 7:51 AM
  • User-832373396 posted

    Sir, the only one another way is to update Protocol, then it could open the client side exe application:

    /// <summary>  
    /// register name;  
    /// </summary>  
    private const string RegName = "WFA";  
    public void UpdateProtocol()  
    {  
        try  
        {  
            if (Registry.ClassesRoot.OpenSubKey(RegName) != null)  
            {  
                RegistryKey rg = Registry.ClassesRoot.OpenSubKey(RegName+"\\shell\\open\\command", true);  
                string   
                    oldUrl = rg.GetValue("").ToString(),  
                    newUrl = string.Format("\"{0}\" \"%1\"", Application.ExecutablePath);  
      
      
                if (!oldUrl.Equals(newUrl, StringComparison.CurrentCultureIgnoreCase))  
                {  
                    rg.SetValue("", newUrl);  
                }  
            }  
            else  
            {  
                RegistryKey first = Registry.ClassesRoot.CreateSubKey(RegName);  
                first.SetValue("", RegName+" Protocol");  
                first.SetValue("URL Protocol", "");  
                RegistryKey  
                    shell = first.CreateSubKey("shell"),  
                    open = shell.CreateSubKey("open"),  
                    cmd = open.CreateSubKey("command");  
                cmd.SetValue("", string.Format("\"{0}\" \"%1\"", Application.ExecutablePath));  
            }  
        }  
        catch (Exception ex)  
        {  
            throw new Exception(" When modifying the register information, it fails. make sure enough permission  ", ex);  
        }  
    }  

    at view page:

    <a href="WFA://str">open the windows application and pass the 'str' as parameter </a>  

    Reference:

    https://msdn.microsoft.com/en-us/library/aa767916.aspx#About_URLs_and_Name

    https://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx 

    Bests,

    Jolie

    Thursday, December 28, 2017 9:44 AM