//这个是个以管理员用户打开cmd执行一串命令的实例
string strPWD = "";//你要调用的指定系统用户的密码,为了安全起见,可以事先加密放在INI或者XML文件中,再以解密方式获取。
SecureString password = new SecureString(); //SecureString,安全字符,必须是char类型
foreach (char c in strPWD.ToCharArray())
{
password.AppendChar(c);
}
Process P = new Process();
P.StartInfo.UseShellExecute = false; //这条属性必须设置为false,否则无法以用户模式运行程序
P.StartInfo.RedirectStandardError = true; //以下3条属性MSDN上有详解
P.StartInfo.RedirectStandardInput = true;
P.StartInfo.RedirectStandardOutput = true;
P.StartInfo.CreateNoWindow = false; //是否显示运行窗口
P.StartInfo.FileName = "cmd.exe"; //调用的程序名
P.StartInfo.UserName = "administrator"; //指定用户名
P.StartInfo.Password = password; //指定明码,必须是安全字符串
P.StartInfo.Domain = "administrators"; //指定用户名所在域,即所在用户组
P.StartInfo.Arguments = "/c"+"shutdown -f -s"; //调用程序执行的命令
P.Start();