An algorithm automatically selects a power state based on device
configuration parameters. The selected power state may then be returned
and/or automatically implemented in a shutdown of the device. The
parameters can include whether the device supports a system battery,
whether the device is connected to an uninterruptible power supply,
whether a value is available for remaining battery life, whether the
device is receiving AC power and/or whether a hibernate fail safe feature
is available. A shutdown failure algorithm may also be included. The
shutdown failure algorithm detects a failed attempt to shut down the
device using a selected power state. The power state selection is changed
and shutdown is then re-attempted. If shutdown again fails, a force
shutdown flag is set. If shutdown again fails, a shutdown failure is
reported.