Handling IRP_MN_QUERY_POWER for System Power States
The power manager sends a power IRP with the minor IRP code IRP_MN_QUERY_POWER and SystemPowerState in Parameters.Power.Type to determine whether it can safely change to a specified system power state (S1-S5) and to allow drivers to prepare for such a change.
Whenever possible, the power manager queries before sending an IRP_MN_SET_POWER that requests a lower (less powered) state. However, in cases of a failing battery or imminent loss of power, the power manager sends the set-power IRP without querying first. The power manager never sends a query before sending an IRP to set the system in the working state (S0).
For information about how a power policy owner for a device handles system query-power requests, see Handling a System Query-Power IRP in a Device Power Policy Owner.
For information about how drivers (that are not the power policy owner for a device) handle system query-power requests, see the following:
Handling a System Query-Power IRP in a Filter or Function Driver
Failing a System Query-Power IRP in a Filter or Function Driver
Handling a System Query-Power IRP in a Bus Driver
Note that a driver must never send a device IRP_MN_SET_POWER request in response to a system query; it requests such an IRP only after it receives a system set-power request.
Because the power manager sends the system query IRP to each device stack on the system, it is possible that a driver for one device might fail the query while drivers for other devices complete it successfully. Beginning with Windows Vista, a change to the system power state to a sleep state is a critical power state change. Even if a driver fails a system query-power IRP, the power manager in Windows Vista might still change the system power state to a sleep state. It is also possible that a battery might expire while a query is active, requiring an immediate shutdown. Consequently, after a query IRP, drivers must be prepared to receive any of the following power IRPs:
An IRP_MN_SET_POWER to the queried state
An IRP_MN_SET_POWER to a different power state
An IRP_MN_SET_POWER to the current power state
An IRP_MN_QUERY_POWER to any state
Usually, however, a driver receives a system set-power IRP following a system query IRP. Regardless, a driver must be ready to change the system power state even if the driver fails a query-power IRP.