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