I need to start a process as another user and it's bombing.
I scaled it down my code to a simple reference example. This code works fine to start the process itself:
var info = new ProcessStartInfo("notepad.exe")
{
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
However, if I add the UserName and Password values:
var info = new ProcessStartInfo("notepad.exe")
{
UserName = "user",
Password = StringToSecureString("password"),
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardError = true,
RedirectStandardOutput = true
};
Process.Start(info);
It bombs with the ever so helpful System.ComponentModel.Win32Exception message:
The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
Just in case, here is the secure 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 alternate solutions would be very much appreciated!
Is your Secondary Logon service started, I believe this is required to start a new process under a different user account?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With