starting process with alternate credentials causes application error

D

DubSport

I am trying to get my .net page to run a simple batch file on my IIS
server. I want it to run with specified credentials. It appears to
start the program cmd.exe as the correct user (shows up in the task
mgr) but it just hangs there and will never finish. Looking in the
event logs I see this:

Application popup: cmd.exe - Application Error : The application
failed to initialize properly (0xc0000142). Click on OK to terminate
the application.

I have no idea why it is hanging like that, can someone help me? Here
is my code:


SecureString pwd = new SecureString();
pwd.Clear();
pwd.AppendChar('1');
pwd.AppendChar('2');
pwd.AppendChar('3');
pwd.AppendChar('4');
pwd.AppendChar('5');
pwd.AppendChar('6');
pwd.AppendChar('7');
pwd.AppendChar('8');
pwd.AppendChar('9');

ProcessStartInfo startInfo = null;
Process batchProcess = null;

startInfo = new ProcessStartInfo();
startInfo.Domain = "somedomain";
startInfo.UserName = "Domainuser";
startInfo.Password = pwd;
startInfo.WorkingDirectory = @"C:\";
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.Arguments = @"/c c:\test.bat";
startInfo.ErrorDialog = false;


batchProcess = new Process();
batchProcess.StartInfo = startInfo;
batchProcess.Start();

System.IO.StreamReader myProcessOut = batchProcess.StandardOutput;
string s = myProcessOut.ReadToEnd();
myProcessOut.Close();
batchProcess.WaitForExit(1000);
if (!batchProcess.HasExited)
batchProcess.Kill();

....Jamie
 
N

Nicholas Paldino [.NET/C# MVP]

Is it possible to log in interactively as this user and check to see if
you can run the program under that user account? Also, if you impersonate
that user for the page (using web.config, or the WindowsIdentity class),
does it work then?
 
W

Willy Denoyette [MVP]

DubSport said:
I am trying to get my .net page to run a simple batch file on my IIS
server. I want it to run with specified credentials. It appears to
start the program cmd.exe as the correct user (shows up in the task
mgr) but it just hangs there and will never finish. Looking in the
event logs I see this:

Application popup: cmd.exe - Application Error : The application
failed to initialize properly (0xc0000142). Click on OK to terminate
the application.

I have no idea why it is hanging like that, can someone help me? Here
is my code:


SecureString pwd = new SecureString();
pwd.Clear();
pwd.AppendChar('1');
pwd.AppendChar('2');
pwd.AppendChar('3');
pwd.AppendChar('4');
pwd.AppendChar('5');
pwd.AppendChar('6');
pwd.AppendChar('7');
pwd.AppendChar('8');
pwd.AppendChar('9');

ProcessStartInfo startInfo = null;
Process batchProcess = null;

startInfo = new ProcessStartInfo();
startInfo.Domain = "somedomain";
startInfo.UserName = "Domainuser";
startInfo.Password = pwd;
startInfo.WorkingDirectory = @"C:\";
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.Arguments = @"/c c:\test.bat";
startInfo.ErrorDialog = false;


batchProcess = new Process();
batchProcess.StartInfo = startInfo;
batchProcess.Start();

System.IO.StreamReader myProcessOut = batchProcess.StandardOutput;
string s = myProcessOut.ReadToEnd();
myProcessOut.Close();
batchProcess.WaitForExit(1000);
if (!batchProcess.HasExited)
batchProcess.Kill();

...Jamie


The application is hanging because there is a dialog box (invisible!)
waiting for a user action "..Click on OK to terminate...".
What application are you trying to start from test.bat?

Willy.
 
D

DubSport

I am able to log in as the specified user and run the .bat file no
problem, it requires no user input at all, and exits automatically.
The .bat file uploads a PDF to a sharepoint site. The specified user
has all necessary permissions from start to finish on files/folders
and sharepoint sites. I have even tried running a very simple dos
command "ipconfig" that requires no user input and same thing, it just
hangs. Is it some sort of security thing with Windows 2003 server
SP2?

I have also tried turning on impersonation in the web.config and also
looked at WindowsIdentity class, neither make a difference.
Anything else you can suggest?

....Jamie
 
W

Willy Denoyette [MVP]

DubSport said:
I am able to log in as the specified user and run the .bat file no
problem, it requires no user input at all, and exits automatically.
The .bat file uploads a PDF to a sharepoint site. The specified user
has all necessary permissions from start to finish on files/folders
and sharepoint sites. I have even tried running a very simple dos
command "ipconfig" that requires no user input and same thing, it just
hangs. Is it some sort of security thing with Windows 2003 server
SP2?

I have also tried turning on impersonation in the web.config and also
looked at WindowsIdentity class, neither make a difference.
Anything else you can suggest?

...Jamie


My guess is that you are running asp.net in the SYSTEM account. Both W2K3
and XP SP2 don't allow you to spawn another process with alternate
credentials when launched from the SYSTEM logon session, you'll need to run
your service (asp.net worker) under the "NetworkService "service account .

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

Top