NTSTATUS NtShutdownSystem ( __in SHUTDOWN_ACTION Action ) /*++ Routine Description: This service is used to safely shutdown the system. N.B. The caller must have SeShutdownPrivilege to shut down the system. Arguments: Action - Supplies an action that is to be taken after having shutdown. Return Value: !NT_SUCCESS - The operation failed or the caller did not have appropriate privileges. --*/ { POWER_ACTION SystemAction; NTSTATUS Status; // // Convert shutdown action to system action // switch (Action) { case ShutdownNoReboot: SystemAction = PowerActionShutdown; break; case ShutdownReboot: SystemAction = PowerActionShutdownReset; break; case ShutdownPowerOff: SystemAction = PowerActionShutdownOff; break; default: return STATUS_INVALID_PARAMETER; } // // Bypass policy manager and pass directly to SetSystemPowerState // Status = NtSetSystemPowerState ( SystemAction, PowerSystemSleeping3, POWER_ACTION_OVERRIDE_APPS | POWER_ACTION_DISABLE_WAKES | POWER_ACTION_CRITICAL ); return Status; }
NTSTATUS NtShutdownSystem( IN SHUTDOWN_ACTION Action ) /*++ Routine Description: This service is used to safely shutdown the system. N.B. The caller must have SeShutdownPrivilege to shut down the system. Arguments: Action - Supplies an action that is to be taken after having shutdown. Return Value: !NT_SUCCESS - The operation failed or the caller did not have appropriate priviledges. --*/ { POWER_ACTION SystemAction; KPROCESSOR_MODE PreviousMode; NTSTATUS Status; // // Convert shutdown action to system action // switch (Action) { case ShutdownNoReboot: SystemAction = PowerActionShutdown; break; case ShutdownReboot: SystemAction = PowerActionShutdownReset; break; case ShutdownPowerOff: SystemAction = PowerActionShutdownOff; break; default: return STATUS_INVALID_PARAMETER; } // // Check to determine if the caller has the privilege to shutdown the // system. // PreviousMode = KeGetPreviousMode(); if (PreviousMode != KernelMode) { // // Check to see if the caller has the privilege to make this // call. // if (!SeSinglePrivilegeCheck( SeShutdownPrivilege, PreviousMode )) { return STATUS_PRIVILEGE_NOT_HELD; } return ZwShutdownSystem(Action); } else { MmLockPagableCodeSection((PVOID)MmShutdownSystem); } // // Prevent further hard error popups. // ExpTooLateForErrors = TRUE; // // Invoke each component of the executive that needs to be notified // that a shutdown is about to take place. // ExShutdownSystem(); IoShutdownSystem(0); CmShutdownSystem(); MmShutdownSystem(); IoShutdownSystem(1); // // If the system is to be rebooted or powered off, then perform the // final operations. // if (Action != ShutdownNoReboot) { DbgUnLoadImageSymbols( NULL, (PVOID)-1, 0 ); if (Action == ShutdownReboot) { HalReturnToFirmware( HalRebootRoutine ); } else { HalReturnToFirmware( HalPowerDownRoutine ); } } // // Bypass policy manager and pass directly to SetSystemPowerState // Status = NtSetSystemPowerState ( SystemAction, PowerSystemSleeping3, POWER_ACTION_OVERRIDE_APPS | POWER_ACTION_DISABLE_WAKES | POWER_ACTION_CRITICAL ); return STATUS_SUCCESS; }