private void TrySessionLogOff() { int rval = Shell32.ExitWindowsEx(Shell32.EWX_LOGOFF | Shell32.EWX_FORCE | Shell32.EWX_FORCEIFHUNG, 0); if (rval == 0) // starting the shutdown failed { this.WriteToEventLog("FATAL: ExitWindowsEx Failed", EventLogEntryType.Error); throw new LogoffException("FATAL: ExitWindowsEx Failed"); } }