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

Posted on 2007-08-06
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
    LVL 6

    Accepted Solution

    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

    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

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Lync server 2013 Backup Service Error ID 4049 – After File Share Migration
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now