参考代码:
http://blog.csdn.net/jinjazz/archive/2008/04/17/2302095.aspx
把这行换成后面说明中的倒数第三条倒数第四条就是关机和重启
p.StartInfo.Arguments = "user32.dll,LockWorkStation";
http://blog.csdn.net/jinjazz/archive/2008/04/17/2302095.aspx
把这行换成后面说明中的倒数第三条倒数第四条就是关机和重启
p.StartInfo.Arguments = "user32.dll,LockWorkStation";
[DllImport( "user32.dll ",ExactSpelling=true,SetLastError=true)]
public static extern bool ExitWindowsEx(int flg, int rea); private const int EWX_LOGOFF = 0x00000000; //注销
private const int EWX_SHUTDOWN = 0x00000001; //关机
private const int EWX_REBOOT = 0x00000002; //重起
ExitWindowsEx(EWX_SHUTDOWN ,0);
private static extern int ExitWindowsEx(int uFlags, int dwReserved);
//注销计算机
public void logout()
{
ExitWindowsEx(0, 0);
}
//关闭计算机
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");
}
//重新启动计算机
public void afreshstartpc()
{
//创建访问控制本地系统进程的对象实例
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 -r -t 0");
}