3
votes

I have the following

[HttpPost]
public IActionResult LaunchExternalProcess()
{
    Process.Start("C:\\Windows\\System32\\calc.exe");
    return Ok();

}

And this works perfectly fine on my local machine, but when deployed onto IIS 10 (windows 2016) I get no errors but it does not launch the calc on the server.

I simply want to call an external .exe from a button on my page.

Here is the javascript that I am using which also works on my local but no errors on server and it displays the success message

$.ajax({
    url: "/Admin/LaunchExternalProcess",
    type: "POST",
    cache: false,

    success: function () {

        console.log("success");
    }
});
2
what permissions would be required to run an external app?Zoinky
Part of the problem here is Calc. When everything went UWP calc went with it, and you can't start a UWP process from a non-interactive session like the one the app pool starts under. So ... does it work with the actual process you're trying to start? (Not that I'd encourage this in any way)blowdart

2 Answers

3
votes

First, it is a very bad idea to spin up an external process like this. So please, don't do this in a real application. You will more than likely create far more issues and security holes that it would ever be worth. There are several, far more robust, architectural patterns for dealing with external processes outside your request pipeline.

That said, the problem here is that calc.exe is failing to launch on your server. Your method doesn't know about this however since you're simply telling it to start a Process, you're not checking to see what state that process is in.

var process = Process.Start("C:\\Windows\\System32\\calc.exe");
if (process == null) // failed to start
{
    return InternalServerError();
}
else // Started, wait for it to finish
{
    process.WaitForExit();
    return Ok();
}
0
votes

AzureWebJob is one of those implementations, not as simple, but it gets the job done