网站首页 博客 C#调用cmd.exe执行关机命令
1 2 3 4 5 6 7 8 9 | using System.Diagnostics;//首先导入这个命名空间Process p = new Process();//实例化一个独立进程p.StartInfo.FileName = "cmd.exe";//进程打开的文件为Cmdp.StartInfo.UseShellExecute = false;//是否启动系统外壳选否p.StartInfo.RedirectStandardInput = true;//这是是否从StandardInput输入p.StartInfo.CreateNoWindow = true;//这里是启动程序是否显示窗体p.Start();//启动p.StandardInput.WriteLine("shutdown -s -t 10");//运行关机命令shutdown (-s)是关机 (-t)是延迟的时间 这里用秒计算 10就是10秒后关机p.StandardInput.WriteLine("exit");//退出cmd |