Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function sets the device power state for a device.

Syntax

DWORD SetDevicePower(
  PVOID 
pvDevice,
  DWORD 
dwDeviceFlags,
  CEDEVICE_POWER_STATE 
DeviceState
);

Parameters

pvDevice

[in] Specifies the device. Must be a valid LPWSTRdevice name, for example, "COM1:". This parameter is interpreted according to dwDeviceFlags.

dwDeviceFlags

[in] Set to POWER_NAME to specify the name of the device that is requesting the power request.

DeviceState

[in] Specifies the desired device power state.

Return Value

ERROR_ACCESS_DENIED

Indicates that the caller does not have the required privileges.

ERROR_FILE_NOT_FOUND

Indicates that the device was not found.

ERROR_INVALID_PARAMETER

Indicates an invalid device ID, flag, or dwStatevalue.

ERROR_SUCCESS

Indicates that the device was found and device power state updated correctly.

ERROR_WRITE_FAULT

Indicates that the attempt to update the device power failed.

Remarks

When SetDevicePoweris called, qualify the name of your device with an associated class. For example, {8DD679CE-8AB4-43c8-A14A-EA4963FAA715}\DSK1:refers to a power-managed block device called DSK1. If no class qualification is present, the generic power-manageable class {A32942B7-920C-486b-B0E6-92A702A99B35}is assumed.

If you specify a power state that is not supported, the Power Manager will set the device to the next highest supported power level, where D0 is a higher level than D1. However, if you specify D3, the Power Manager will set the device to D4, if D4 is supported. Otherwise the device is set to the next higher supported power level.

Applications should avoid using this function because it greatly restricts device power self-management. They should use the SetPowerRequirementcall instead. Set the device power state to PwrDeviceUnspecifiedto allow normal power management to resume.

See Also

Other Resources

Power Management Functions