System.Diagnostics.Process.Start("c:\\cmd.exe", @"shutdown -s -t 60");
解决方案 »
- winfrom dataGridView 指定列可编辑
- c# datagridView的button列
- 有谁做过数字图像的呢, 如何识别出来?
- 如何使用wininet的InternetSetOptionA设置ftp超时时间
- RichTextBox图文混编的问题
- 关于new函数的一个传值的问题
- 用Remoting之后,客户端和服务器端都要用共享类.dll,那说明客户端没有和sql语句分开吗?
- 好奇怪, 为什么得不到 TextBox 的值呢??????
- 关于C#向ACCESS存路径问题
- 先用AcceptChanges,后用ds.UpDate不能将数据更新到资料库,去掉AcceptChanges,只用ds.UpDate就可以,为什么?
- c#和sql 与 java和oracle问题
- teechart c#问题。急!!!!!!!
System.Diagnostics.Process.Start("shutdown", @" -s -t 60 -f");
我用这个 只出现了个DOS窗口, 却没执行后面的关机命令啊。
System.Diagnostics.Process.Start("shutdown", @" -s -t 60 -f");
System.Diagnostics.Process.Start("shutdown", @" -s -t 60 -f");
确实直接调用shutdown就可以了
这是一种方法楼主如果要使用cmd,是这样的:
Process.Start("cmd","/c shutdown -s -t 0");
自己看看cmd的帮助吧 (cmd /?)
/c表示调用完成后关闭cmd窗口
/k表示不关闭
[DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)] //关闭计算机
public void closepc()
{
//创建访问控制本地系统进程的对象实例
System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
myprocess.StartInfo.FileName = "cmd.exe";
myprocess.StartInfo.UseShellExecute = false;
myprocess.StartInfo.RedirectStandardInput = true;
myprocess.StartInfo.RedirectStandardOutput = true;
myprocess.StartInfo.RedirectStandardError = true;
myprocess.StartInfo.CreateNoWindow = true;
myprocess.Start();
myprocess.StandardInput.WriteLine("shutdown -s -t 0");
}