using System.Diagnostics; using System.Runtime.InteropServices;
Process.Start("shutdown","/s /t 0"); // starts the shutdown application // the argument /s is to shut down the computer // the argument /t 0 is to tell the process that // the specified operation needs to be completed // after 0 seconds
Process.Start("shutdown", "/r /t 0"); // the argument /r is to restart the computer
[DllImport("user32")] public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);
ExitWindowsEx(0,0);
[DllImport("user32")] public static extern void LockWorkStation();
LockWorkStation();
[DllImport("PowrProf.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent);
SetSuspendState(true, true, true);
SetSuspendState(false, true, true);