Aqib Javed
Aqib Javed

Reputation: 105

ASP.NET Process.Start work background in task Manger but not come on front on IIS8.5 (Windows 8.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)

Upvotes: 1

Views: 1671

Answers (2)

Aqib Javed
Aqib Javed

Reputation: 105

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.

Upvotes: 1

GPW
GPW

Reputation: 2626

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.

Upvotes: 1

Related Questions