I need to start the process as another user, and he is bombing.
I reduced it to my code to a simple reference example. This code works great to start the process itself:
var info = new ProcessStartInfo("notepad.exe")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
However, if I add the values UserNameand Password:
var info = new ProcessStartInfo("notepad.exe")
{
UserName = "user",
Password = StringToSecureString("password"),
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
Process.Start(info);
It bombs a very useful System.ComponentModel.Win32Exception message:
A service cannot be started either because it is disabled or because it does not have any associated devices with it.
Just in case, this is a safe string conversion method:
private static SecureString StringToSecureString(string s)
{
var secure = new SecureString();
foreach (var c in s.ToCharArray())
{
secure.AppendChar(c);
}
return secure;
}
Any ideas or alternative solutions would be greatly appreciated!
source
share