public static bool ExitWindows(ExitWindows exitWindows, ShutdownReason reason, bool ajustToken)
 {
     if (ajustToken && !TokenAdjuster.EnablePrivilege("SeShutdownPrivilege", true))
     {
         return(false);
     }
     return(ExitWindowsEx(exitWindows, reason) != 0);
 }
Пример #2
0
        /// <summary>
        ///     Requests a system reboot.
        /// </summary>
        /// <returns>Returns true if the request was successful, false otherwise.</returns>
        public static bool Reboot()
        {
            if (!TokenAdjuster.EnablePrivilege("SeShutdownPrivilege", true))
            {
                return(false);
            }

            return(ExitWindowsEx(ExitWindows.Reboot, ShutdownReason.MajorOther | ShutdownReason.MinorOther));
        }
Пример #3
0
        private void Reboot()
        {
            Log(LogLevel.Error, $"Rebooting system.");

            try
            {
                if (!TokenAdjuster.EnablePrivilege("SeShutdownPrivilege", true) ||
                    !ExitWindowsEx(ExitWindows.Reboot | ExitWindows.ForceIfHung, ShutdownReason.MinorInstallation))
                {
                    Log(LogLevel.Error, $"Failed to reboot: {Marshal.GetLastWin32Error()}");
                }
            }
            catch (Exception ex)
            {
                Log(LogLevel.Error, $"Failed to reboot: {ex}");
            }

            Bootstrapper.Engine.Quit(MainViewModel.Status);
        }