2009/01/06

C# 從程式內呼叫程式,以特定使用者呼叫 Process.StartInfo



Process pro = new Process();
pro.StartInfo.UserName = "aaa_iuser"; // 指定以特定使用者執行
string pw = "P@$$w0rd";
SecureString ss = new SecureString(); // password 要以SecureString傳入,而且一定要給password = =
foreach (char c in pw)
{
ss.AppendChar(c);
}
pro.StartInfo.Password = ss;
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.FileName = "notepad.exe";
pro.Start();

90% 症候群