-2

C# code uses Process.Start to run an exe that is held locally on the same PC where the code is running. In Visual Studio this works fine and the exe is called and the cmd window pops up. Once the exe finishes, control is then passed back to the C# calling application. However, once the web application is published to local IIS, with the application pool identity set to a custom account this no longer works. The exe is viewable in the task manager as a running process, however the cmd window does not pop up to indicate to the user that it is running. No errors are caught by the try/catch block. The application pool identity does have permissions to run the exe. How can i ensure that the cmd window is viewable to the user in IIS, as it is in Visual Studio?

LeedsWalker
  • 189
  • 1
  • 3
  • 13
  • Is the EXE running as the user that's logged into the web server watching it? – mason May 04 '16 at 21:01
  • The iis application pool is running under a custom user account which has administrator access. I've also tested logging on to the PC with this same user, as suggested and unfortunately the same issue resides. This user does have permissions to run the exe. – LeedsWalker May 04 '16 at 21:27
  • But does the EXE do what it needs to or not? Why do you need to see the CMD window pop up? IIS processes are not interactive processes. – Nick.Mc May 13 '16 at 08:18

2 Answers2

2

Microsoft does not recommend calling an .exe from a Web application as w3wp.exe runs in a sandboxed environment for security reasons and hence any thread/task/process that it launches is not the same as it would be when you launch it yourself and hence may not work as expected.

You may want to re-code the console applications as ASP.NET Web API (formerly WCF), possibly hosted in IIS or in a Windows Service.

Similar question.

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
  • 3
    Web API is NOT WCF. They are completely different technologies. https://msdn.microsoft.com/en-us/library/jj823172(v=vs.110).aspx – Xavier J May 04 '16 at 21:22
  • Web API is continuation of older soap based technology. It does not alter the point of my answer but thanks for pointing out the new vs old... – IrishChieftain May 04 '16 at 21:25
  • OK, thanks for your comments, that's a disappointment as I'm not so keen on re-writing it all!... – LeedsWalker May 04 '16 at 21:31
  • Way back I did something similar and got it to work: http://www.codersbarn.com/post/2011/11/08/Calling-Console-Application-from-Web-Form.aspx – IrishChieftain May 04 '16 at 21:35
  • http://www.codedigest.com/Articles/ASPNET/334_Working_with_exe_in_ASPNet-Calling_KillingAborting_an_exe.aspx – IrishChieftain May 04 '16 at 21:38
0

I resolved this issue by using JavaScript. I added an "OnClientClick" event to my button and this initiated my javascript function. This function created a new ActiveXObject and then ran the file in question. This now works successfully via IIS.

LeedsWalker
  • 189
  • 1
  • 3
  • 13
  • 1
    If it's running in javascript it's probably running on the client rather than the server. This is probably not going to function on a locked down client. – Nick.Mc May 15 '16 at 22:53