1

i want to execute a .EXE file in mvc 3 application when we run this project locally on browser it work perfectly . Problem is that when we publish this project and host it on the IIS(8.5) server on window 8.1 when we click the button code executed and process start in Task Manger but app not shown on front .
For examples in this case we execute notepad.exe file .
Following is our code in html we make a one button when user click on that button controller method is called that run code .
when user click on button this is cod that is executed.

 $("#Button11").click(function (event) {

    $.post("/Account/Start_Appl", {}, function (data) {

    });

    event.preventDefault();
});

and start Start_Appl Method inside Account controller have following line of code .

 public string Start_Appl()
    {    string path="C:\\Windows\\System32\\notepad.exe";
         ProcessStartInfo psi = new ProcessStartInfo();
         psi.UseShellExecute = true;
         psi.LoadUserProfile = true;
         psi.WorkingDirectory = path;
         psi.FileName = path;

         Process.Start(psi);


        return "ok";

    }

i want to execute .EXE file with iis(8.5) any solution to this problem . i check on the internet but can not find any proper solution for this problem.
i also check this link but not give any help .
ASP.NET Process.Start not working on IIS8 (Windows 8.1)

Aqib Javed
  • 105
  • 9
  • I would imagine your issue is permissions, but TBH it could be anything. Why do you want a web page that opens notepad on the server? o_O Seems pretty pointless – Liam Dec 04 '17 at 14:31
  • 1
    The process running the site in IIS is not a user-facing one. Hence you can't see it. The only way I could think to do this is to write a separate Application (console app, winforms, tray application, etc) which runs as the local user and waits for a signal of some sort. you make your web app send this signal, then the console app launches the program. Though I also have to point out that this seems to be a weird thing to do and doesn't make a great deal of sense.... – GPW Dec 04 '17 at 14:35
  • Some things to think about: - What do you do when multiple users press the button at once? What do you do when one user accidentally presses the button more than once (the controller won't necessarily know it's the same person unless you add a lot of code) - what do you do if the application decides it wants user input (e.g. has an error, runs out of disk space, automatically detects an available update and asks user if they want it, etc).. Tell us what problem you think this 'solution' will solve. There is a better way than this. – GPW Dec 04 '17 at 14:39
  • @GPW can you tell me some detail how my web app will send signal to the desktop application to open exe file . – Aqib Javed Dec 04 '17 at 15:13
  • Note pad is just an examples i want to open any other exe file. --@Liam – Aqib Javed Dec 04 '17 at 15:15
  • @AqibJaved it could create a file in a folder being watch by the app; it could use one of many message queuing systems; it could listen for a 'ping' on a particular TCP port; it could monitor a table in a database; there are lots of ways that could work. what are you actually trying to achieve here? – GPW Dec 04 '17 at 17:18
  • @GPW i just want to open any application installed on local machine. it could be any program like notepad, word pad , paint etc. just help me in this regard leave the remaining purpose of the app – Aqib Javed Dec 04 '17 at 17:24
  • That’s just what should happen. Learn about Windows session isolation and then you know why. – Lex Li Dec 04 '17 at 21:18

2 Answers2

1

OK, first off, this is a very odd thing to do - there is going to be a better approach for whatever your problem is. That said, what I would do in this situation is:

  1. create a database with a JOB_QUEUE table. exactly what is in this table is up to you, but I'd suggest an ID, a date_added, something to indicate what the job should consist of (e.g. the name of the exe to run?) and a flag to indicate the status of the job (pending/in progress/failed/completed)
  2. modify controller to insert a record into this table with a 'pending' status (this is ALL it does)
  3. write a separate application that runs in a user process (windows forms or console application). this application could run on the server which hosts IIS or a separate one - all it needs it access to the same database
  4. Make this separate application periodically check the job queue table for jobs with a pending status.
  5. When a new job is detected, the application updates the database so the job is 'in progress' and runs the job. if successful it updates the job to be 'completed' and if it fails it updates it to be 'failed'.
  6. It then goes back to simply monitoring the table.

There are lots of other things you could use in place of the database for a queue, but this would be quick to write and easy to debug/test as well as making it easy to add multiple clients and persist historical info, and add controller methods to report on jobs requested/completed and progress.

GPW
  • 2,528
  • 1
  • 10
  • 22
  • For second app that launch an .exe file we host that app on iis server or run locally on a computer . – Aqib Javed Dec 05 '17 at 13:37
  • As long as it can connect to the database you could run it anywhere. If running on the server running IIS though you'd need to run it as a logged-on user though - so connect to the server via remote desktop or something... Personally I'd host it on a different PC. – GPW Dec 05 '17 at 13:59
1

For execution external .exe file in iis(8.5) and window 8.1 . we used
Custom URL Protocol for Invoking Application Techniques check this link
Custom URL Protocol
i have change my Start_Appl function is as .

public string Start_Appl()
    {
        try
        {

            string myAppPath = "C:\\Windows\\System32\\notepad.exe";

            RegistryKey key = Registry.ClassesRoot.OpenSubKey("myAppa");  //open myApp protocol's subkey

            if (key == null)  //if the protocol is not registered yet...we register it
            {
                key = Registry.ClassesRoot.CreateSubKey("myAppa");
                key.SetValue(string.Empty, "URL: myApp Protocol");
                key.SetValue("URL Protocol", string.Empty);

                key = key.CreateSubKey(@"shell\open\command");
                key.SetValue(string.Empty, myAppPath + " " + "%1");

            }

            key.Close();

        }
        catch (Exception e) {
            return e.Message.ToString();
        }



        return "ok";

    }

we first register a key if it is not already create and set value and after that we make a button on my aspx page is as

  <input type="submit" name="Launch" id="Launch" value="Launch Custom URL" onclick="LaunchURLScript()">  

When user click on button the function LaunchURLScript is call and inside this function we write following code in it

  function LaunchURLScript() {
    $.post("/Account/Start_Appl", {}, function (data) {

        if (data = "ok") {
            alert("ok");
            var url = "myAppa:"; window.open(url); self.focus();
        }

    });

}  

for inside we first call controller method to make URl protocol if not already exist and finally we open new window that lunch my note pad exe file .
in this way we solve our problem.

Aqib Javed
  • 105
  • 9