Unless a device is enabled for wake-up, its drivers power it off when the system shuts down. Devices must always be powered off upon removal or surprise removal.
When a device is removed, the Plug and Play manager sends an IRP_MN_REMOVE_DEVICE request to the device stack. In response to this IRP, the drivers for the device should ensure that the device powers down. Powering down the device is an implicit part of removal handling; the device power policy owner is not required to send an IRP_MN_SET_POWER for PowerDeviceD3.
As drivers handle the IRP_MN_REMOVE_DEVICE request, they wait for pending I/O to complete, perform any necessary removal processing, call PoSetPowerState to notify the power manager that the device is in state D3, and delete the device objects they created for this device. Typically, the bus driver turns off power to the device.
If a device is unexpectedly removed from a Windows 2000 or later operating system, the Plug and Play manager sends an IRP_MN_SURPRISE_REMOVAL request to the top of the corresponding device stack. In response to this IRP, the drivers for the device should perform surprise removal processing, as described in Handling an IRP_MN_SURPRISE_REMOVAL Request.
At system shutdown, the power manager sends an IRP_MN_SET_POWER for a system power state (either S4 or S5). When the device power policy owner receives this IRP, it should send an IRP_MN_SET_POWER for PowerDeviceD3 so that lower drivers can finish their work and power down the device.
A driver can optionally perform idle detection for its device, or can request that the power manager perform idle detection, so that the device can be powered down when not in use. For further information, see Detecting an Idle Device.