.NET 4: Process.Start using credentials returns empty output

Posted by alexey on Stack Overflow See other posts from Stack Overflow or by alexey
Published on 2010-05-11T15:19:27Z Indexed on 2010/05/11 15:24 UTC
Read the original article Hit count: 330

Filed under:
|
|

I run an external program from ASP.NET:

var process = new Process();
var startInfo = process.StartInfo;

startInfo.FileName = filePath;
startInfo.Arguments = arguments;

startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;

process.Start();

process.WaitForExit();

Console.Write("Output: {0}", process.StandardOutput.ReadToEnd());
Console.Write("Error Output: {0}", process.StandardError.ReadToEnd());

Everything works fine with this code: the external program is executed and process.StandardOutput.ReadToEnd() returns the correct output.

But after I add these two lines before process.Start() (to run the program in the context of another user account):

startInfo.UserName = userName;
startInfo.Password = securePassword;

The program is not executed and process.StandardOutput.ReadToEnd() returns an empty string. No exceptions are thrown.

userName and securePassword are correct (in case of incorrect credentials an exception is thrown).

How to run the program in the context of another user account?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about .net4