Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to execute *.exe in server from ASP.net

Tags:

My current situation is that I need to execute an exe(which creates a local .txt file) in remote server with IIS hosting an ASP.net/C# API. I created a local user(say userA) as admin to run the web service in the remote server but the .txt file was not created. I already checked and granted necessary folder permissions to userA and added the user in various groups. The funny thing is that if i am logged in as userA in the remote system, the exe gets executed as expected. If i log out then it fails. Server is Win server 2008 with IIS 7. Any help would be appreciated thanks.

UPDATE: I've solved the issue and posted the answer and a few links to related issues here on SO. In short, I needed to set 'load user profile' true in IIS app pool.

Thanks everyone for their contribution

EDIT: Code extracted from comments

Process proc = new Process(); 
proc.StartInfo.FileName = path; 
proc.StartInfo.Arguments = exeparams; 
proc.Start(); 
proc.WaitForExit(); 
stat = proc.ExitCode; 
if (stat != 0) 
{ 
    throw new Functions.log("Error"); 
} 
like image 781
santhosh.v Avatar asked Dec 01 '12 10:12

santhosh.v


People also ask

What is exe in asp net?

An EXE is a program that can be executed( Ex. Windows Program) 2. An Application can have multiple instances of itself running on the system simultaneously. Nov, 2012 9.

Can we open .exe file in browser from server?

No, it is not possible to open a .exe file in the browser. Internet Explorer can open ActiveX controls, and browsers with Java can load applets, but nether is a Windows executable file like you seem to want.


1 Answers

UPDATE: I managed to solve the issue after many weeks. Thank you all for your contribution. Apparently IIS does not load windows user profiles by default. So when running as a different user who is not logged on, their windows profile must be loaded by IIS. In advanced setting menu of your app pool, there is an option "load windows profile" I just changed this to true. In prior versions of IIS, this was set to 'true' by default.

Related questions on SO with same solution:

1) Security exceptions in ASP.NET and Load User Profile option in IIS 7.5

2) Running a asp.net web application project on IIS7 throws exception

3) System.Web.AspNetHostingPermission Exception on New Deployment

Another 4) http://geekswithblogs.net/ProjectLawson/archive/2009/05/05/iis-system.web.aspnethostingpermission-exception-on-windows-7-rc.aspx

like image 120
santhosh.v Avatar answered Oct 15 '22 09:10

santhosh.v