using System.Diagnostics.Process

  • Thread starter Thread starter Morten
  • Start date Start date
M

Morten

Hi!

Does anyone know why the code below always returns an "access is denied"
error?

private void Page_Load(object sender, System.EventArgs e)
{

System.Diagnostics.Process meProc = System.Diagnostics.Process.Start
("cmd.exe", " /c echo y| CACLS C:\\Temp /E /T /G test:F");

meProc.StartInfo.UseShellExecute = false;
meProc.StartInfo.CreateNoWindow = true;
meProc.StartInfo.RedirectStandardError = true;
meProc.StartInfo.RedirectStandardOutput = true;

meProc.Start();
string output = meProc.StandardError.ReadToEnd();
meProc.WaitForExit();

Response.Write (output);
}

I've specified that impersonation should be used in web.config (<identity
impersonate="true"/>) and I've specified that the anonymous user should be
"Administrator" on the virtual directory that I'm using for my web
application.

Help is appreciated.

Morten
 
This is the normal behavior, when using System.Diagnostics.Process.Start,
the new process uses the token for the calling process, not the
impersonation token of the calling thread.
To spawn other processes you need to run the asp.net worker process as
administrator, something I would never suggest. Much better is to run this
code from a COM+ out-proc application that runs with a fixed administrators
identity.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top