[C#] 调用有管理员权限的CMD

ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
                startInfo.RedirectStandardInput = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardError = true;
                startInfo.UseShellExecute =false ;
                startInfo.Verb = "RunAs";
                Process process = new Process();
                process.StartInfo = startInfo;
                process.Start();
                process.StandardInput.WriteLine("bcdedit");
                process.StandardInput.WriteLine("exit");
                string strRst = process.StandardOutput.ReadToEnd();
                Bootinitext.AppendText("\n"+strRst );
                process.WaitForExit();

 

posted @ 2012-04-10 09:14  SpeakHero  阅读(5494)  评论(0编辑  收藏  举报