I try to start a process as a different user. I have an ASP .NET server and want to start a script (at first a simple echo "Hello World" batch file). If I do this:
Process.Start(filepath);
it works, so even this:
Process proc = new Process();
ProcessStartInfo info = new ProcessStartInfo()
{
info.FileName = filepath;
info.Arguments = args;
info.WorkingDirectory = Path.GetDirectoryName(filepath);
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.UseShellExecute = false
)};
proc.StartInfo = info;
proc.EnableRaisingEvents = true;
proc.Exited += new EventHandler(proc_Exited);
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
So here is my problem, if I do it with username and password for example:
info.UserName = "USER";
string password = "PASSWORD";
SecureString passw = new SecureString();
foreach (char c in password)
passw.AppendChar(c);
info.Password = passw;
It won´t work. The Windows Eventlog says "User successfully logged in (USER)" so the login is correct (username/password). When I connect (remote) to the server, I can rightclick the batchfile and "run as different user" with USER and PASSWORD (same as in my program) and it works, so the user has access/permission to execute the batchfile.
The strange thing is, that I get no error in my program, the process starts, but exits immediately with exitcode -1073741502. In the Windows Eventlog (System) I get the information (in my opnion an error)
Application Popup: cmd.exe Could not initialize the application (0xc0000142). Click "OK" to close the application.
I can try to execute a batchfile, cmd.exe directly (with fullpath) or start another exe file. I can always do rightclick "run as different user", I can always do Process.Start, but I cannot do it (Process.Start) with different user (with username and password).
User contributions licensed under CC BY-SA 3.0