Beispiel #1
0
        /// <summary>
        /// Logs off the current user, shuts down the system, or shuts down and restarts the system. It sends the WM_QUERYENDSESSION message to all applications to determine if they can be terminated.
        /// </summary>
        /// <param name="flags">Specifies the type of shutdown.</param>
        /// <param name="reason">The reason for initiating the shutdown.</param>
        /// <returns>If the function succeeds, the return value is nonzero.<br></br><br>If the function fails, the return value is zero. To get extended error information, call Marshal.GetLastWin32Error.</br></returns>
        public static bool ExitWindows(ExitWindowsFlags flags = ExitWindowsFlags.EWX_LOGOFF, SystemShutDownReason reason = SystemShutDownReason.SHTDN_REASON_UNKNOWN)
        {
            var reqPriv = (flags & (ExitWindowsFlags.EWX_POWEROFF | ExitWindowsFlags.EWX_REBOOT | ExitWindowsFlags.EWX_SHUTDOWN)) != 0;

            using (new PrivilegedCodeBlock(reqPriv ? new [] { SystemPrivilege.Shutdown } : new SystemPrivilege[0]))
                return(ExitWindowsEx(flags, reason));
        }
Beispiel #2
0
 private static extern int ExitWindowsEx(ExitWindowsFlags uFlags, ShutdownReason dwReason);
Beispiel #3
0
 public static extern bool ExitWindowsEx(ExitWindowsFlags flags, int reason);
 static extern bool ExitWindowsEx(ExitWindowsFlags uFlags, long dwReason);
 public static extern bool ExitWindowsEx(ExitWindowsFlags uFlags, ShutdownReason dwReason);
Beispiel #6
0
 public static extern bool ExitWindowsEx(ExitWindowsFlags flags, int reason);
Beispiel #7
0
 public static bool ExitWindows(ExitWindowsFlags flags, ShutDownReasonFlags reason = ShutDownReasonFlags.MajorOtherIssue)
 {
     return(ExitWindowsEx(flags, reason));
 }
Beispiel #8
0
 internal static extern bool ExitWindowsEx(ExitWindowsFlags uFlags, ShutDownReasonFlags uReason);