public static bool ExitWindows(ExitWindows exitWindows, ShutdownReason reason, bool ajustToken) { if (ajustToken && !TokenAdjuster.EnablePrivilege("SeShutdownPrivilege", true)) { return false; } return ExitWindowsEx(exitWindows, reason) != 0; }
private void ExecutePowerAction(string choosenAction) { ExceptionHandler.LogEvent("[Countdown] Executing power action"); ignoreClose = false; // do not ignore close event allowClose = true; // disable close question switch (choosenAction) { case "Shutdown": ExitWindows.Shutdown(!Graceful); break; case "Restart": ExitWindows.Reboot(!Graceful); break; case "Hibernate": Application.SetSuspendState(PowerState.Hibernate, false, false); break; case "Sleep": Application.SetSuspendState(PowerState.Suspend, false, false); break; case "Logout": ExitWindows.LogOff(!Graceful); break; case "Lock": ExitWindows.Lock(); break; } if (PreventSystemSleep) { ExceptionHandler.LogEvent("[Countdown] Clearing EXECUTION_STATE flags"); ExecutionState.SetThreadExecutionState(ExecutionState.EXECUTION_STATE.ES_CONTINUOUS); // Clear EXECUTION_STATE flags to allow the system to go to sleep if it's tired. } }
private void tmrClock_Tick(object sender, System.EventArgs e) { //计时减一 this.maxTimeNumber = maxTimeNumber - 1; if (this.maxTimeNumber == 0) { //关机时间到,执行关机操作 //关闭计时器控件 this.tmrClock.Stop(); //实例化ExitWindows类 objExitWindows = new ExitWindows(); bool ok = objExitWindows.Close(); if (!ok) { MessageBox.Show("由于某种原因,无法完成操作"); } } else { //显示提示信息 this.lblMessage.Text = "离自动关机时计时间还有 " + this.maxTimeNumber.ToString() + " 秒"; } }
public ShuntDone() { InitializeComponent(); //获取当前日期 DateTime objDateTime = System.DateTime.Now; //获取当前日期 string currentDate = objDateTime.ToLongDateString(); //获取当前时间 string currentTime = objDateTime.ToLongTimeString(); //在界面上显示当前日期和时间 this.textDateTime.Text = currentDate + "" + currentTime; //给 DateTimePicker控件赋值 this.dtpCurrentDate.Value = objDateTime; //给 DateTimePicker控件赋值 this.dtpCurrentTime.Value = objDateTime; //启动定时器 this.tmrMainClock.Start(); //不显示系统托盘 this.notifyIcon1.Visible = false; //实例化ExitWindows类 objExitWindows = new ExitWindows(); this.lblState2.Text = "未启动"; }
private static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
/// <summary> /// Used to logoff, shutdown or reboot. /// </summary> /// <param name="flags">The type of exit to perform.</param> /// <param name="reasons">The reason for the exit.</param> /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns> public static bool WindowsExit(ExitWindows flags, ShutdownReasons reasons) { EnableToken("SeShutdownPrivilege"); return ExitWindowsEx((int)flags, (int)reasons) != 0; }
static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
public static extern bool ExitWindowsEx(ExitWindows uFlags, int dwReason);
private static extern bool ExitWindowsEx(ExitWindows uFlags, int dwReason);
private static extern bool ExitWindowsEx(ExitWindows uFlags, int dwReason);
internal static extern int ExitWindowsEx (ExitWindows exitFlags, ShutdownReason shutDownReason);
public static extern int ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
public void unmanagedExitWindows(ExitWindows flag) { bool blOK; TokPriv1Luid tp; IntPtr hproc = GetCurrentProcess(); IntPtr htok = IntPtr.Zero; blOK = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED; blOK = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid); blOK = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); blOK = ExitWindowsEx(flag, ShutdownReason.MinorOther); }
public static int ExitWindows(ExitWindows exitWindows, ShutdownReason reason) { return(ExitWindowsEx(exitWindows, reason)); }
public static extern Boolean ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
internal static extern bool ExitWindowsEx(ExitWindows flg, ShutdownReason rea);
internal static extern bool ExitWindowsEx(ExitWindows flg, ShutdownReason rea);
private static void PerformExit(ExitWindows action) { TokPriv1Luid tp; IntPtr hproc = GetCurrentProcess(); IntPtr htok = IntPtr.Zero; OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok); tp.Count = 1; tp.Luid = 0; tp.Attr = SE_PRIVILEGE_ENABLED; LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid); AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero); ExitWindowsEx((uint)action, (uint)ShutdownReason.FlagPlanned); }