3

First off i have checked the web to try and find an answer however i have only come across people who want to run their processes in the background whereas my issue here is the opposite way round.

I have entered the following code on my controller whereby the process is initiated when the button is clicked:

string fileLocation = @"C:\somefolder\anotherFolder\...\application.exe";
        ProcessStartInfo oStartInfo = new ProcessStartInfo();
        oStartInfo.FileName = fileLocation;
        oStartInfo.UseShellExecute = false;
        oStartInfo.CreateNoWindow = true;
        oStartInfo.WindowStyle = ProcessWindowStyle.Normal;
        oStartInfo.CreateNoWindow = false;
        var process = new Process { StartInfo = oStartInfo, EnableRaisingEvents = true };
        process.Start();

now I have run the code and it is executing the exe or so it would appear when i open up the task manager. But i cant seem to get this to execute in the foreground so the user can do what they need to do.

*Extra Information

  • Whenever i try to rebuild after running there is an issue because the exe is in the same solution as the web part of the project, but the issue is the fact i have to go to task manager and kill the process as otherwise it cant access the .exe -- this is another major reason i need to run it in the foreground

  • Visual Studio 2013 Express for web

  • Entity Framework
  • MVC Asp.Net web project

Any help would be really great!

harrison
  • 79
  • 1
  • 11

1 Answers1

1

Please see here: Process.Start method:

ASP.NET Web page and server control code executes in the context of the ASP.NET worker process on the Web server. If you use the Start method in an ASP.NET Web page or server control, the new process executes on the Web server with restricted permissions. The process does not start in the same context as the client browser, and does not have access to the user desktop.

So, the process will run server side, not client side, and it will also run in the user profile of the ASP.Net worker process (w3wp.exe), which means you will not see the process Window unless you happen to be logged in interactively in the same profile.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Polyfun
  • 9,479
  • 4
  • 31
  • 39
  • No its not a duplicate as that doesnt at all answer my question because i need it to run in the foreground, unless you are trying to say that is not possible? I know from what you said its not meant to have access to the user desktop but is it not capable of being reconfigured to run as a normal exe on the desktop side - as if i were literally running a console app from visual studio? – harrison Jan 22 '15 at 14:12