In my .net web application, I need to launch another program as a new process – under a different user account (one with higher priviledges). My code runs without error, but I never get any output (I’ve tried Redirecting the output), and the program doesn’t seem to execute at all. Its not an error with the User auth details, I’ve tried a bogus username and sure enough it throws a valid exception in that case. Nothing gets added to the event log.
SecureString passwordString = new SecureString();
foreach (char c in "MyPassword")
{
passwordString.AppendChar(c);
}
var process = new System.Diagnostics.Process
{
StartInfo =
{
UserName = "myuser", Password = passwordString, Domain = "MyDomain",
WorkingDirectory = HttpContext.Request.MapPath("~/bin"),
UseShellExecute = false,
FileName = HttpContext.Request.MapPath("~/bin") + "\\ServerCertificateImporter.exe",
Arguments = instanceLocationId.ToString(),
CreateNoWindow = true,
RedirectStandardInput = false,
RedirectStandardOutput = false,
RedirectStandardError = false
}
};
process.Start();
process.WaitForExit();
process.Close();
As Yahia pointed out, this was caused by the fact that I was trying to call a program with a different user account – and windows didn’t want me to do that.