I want to launch a process under another username\'s credentials. This is what I have now:
///
/// Do actions under another
May be you forgot to make read only secure string? My method works fine for me:
Process proc = new Process
{
StartInfo =
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
FileName = "cmd.exe",
UserName = "user",
Domain = "myDomain",
Password = GetSecureString("Password"),
Arguments = "/c ipconfig"
}
};
proc.Start();
GetSecureString() function:
public static SecureString GetSecureString(string str)
{
SecureString secureString = new SecureString();
foreach (char ch in str)
{
secureString.AppendChar(ch);
}
secureString.MakeReadOnly();
return secureString;
}