c#中的Process类可方便的调用外部程序,所以我们可以通过调用cmd.exe程序 加入参数 "/c " + 要执行的命令来执行一个dos命令 (/c代表执行参数指定的命令后关闭cmd.exe /k参数则不关闭cmd.exe)
Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/k shutdown -a"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.CreateNoWindow = false; p.Start(); Response.Write(p.StandardOutput.ReadToEnd());
转载于:https://www.cnblogs.com/zzuhjf/archive/2012/07/03/2574767.html
相关资源:C#执行DOS命令的方法