Windows Server 2003 ASP.NET Web Service getting Access Denied when running System.Diagnostics.Process

Posted on 2007-08-06
Medium Priority
Last Modified: 2013-11-05
I have a ASP 2.0 .NET C# Web Service. This web service's goal is to run a command line .EXE application. To do this, I create a Process, assign it some variables, and let it rip. It works great on my local machine, but when I put it on my 2003 Web Server, it fails. I highly suspect it is a permissions issue, however I dont know a lot about IIS. Here is a code snippet:

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.Password = mySecure;
myProcess.StandardInput.AutoFlush = true;
myProcess.StandardInput.Write(myPath + System.Environment.NewLine);
myProcess.StandardInput.Write(myCommand + System.Environment.NewLine);
myProcess.StandardInput.Write("exit" + System.Environment.NewLine);
myreturn = myProcess.StandardOutput.ReadToEnd();

Now at this point it doesnt matter what I am doing with this app. I changed it to CMD.EXE, and it dies at the same point: When I execute the Start() method.

Error Message:
System.ComponentModel.Win32Exception: Access is denied at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start()

What should I do to make this work?
Question by:ALogvin

Accepted Solution

Da1King earned 1000 total points
ID: 19642337
The problem is when your web server attempts to execute this code it does so as IUsr_<computername> account.  More then likely this account doesn't have the necessary permissions to perform the operation.  This leaves you two choices...

Add the permissions to the IUsr account.  However this is a huge security risk.

Change your IIS server to not allow anonymous access and implement 'Integrated Windows Authentication'.  However once implemented you will always be prompted with a username and password box asking you for your credentials.  This allows the web page processes to work as if they were you using your account.

So you have security on one hand and convenience on the other.
LVL 28

Assisted Solution

strickdd earned 1000 total points
ID: 19648795
There is another slightly more secure alternative. You can create a new user (on the computer or on the domain) and apply it as the IIS webuser (Control Panel > Administrative Tools > Internet Information Services | right click on the website > Properties | Directory Security > Anonymous Access and authentication control > Edit | Change Anonumous user to this new user).

Once you have the user applied to the site, you can restrict the rights of System.Diagnostics to just this user instead of the generic user used for every site.

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question