0

I'm looking for a programmatic way of querying an Display Adapter's current power state (d-state) in Windows. It's not a USB device or ACPI device. I couldn't find much on how I could access the current d-state through cmd line or an API. It could also be seen in the device manager adapter's detail info.

Display Adapter's detail tab showing the device power state

logic that i have written :

#include <windows.h>
    #include <setupapi.h>
    #include <devguid.h>
    #pragma comment (lib, "SetupAPI.lib")
    int DeviceManager::GetDeviceDriverPowerData() {
        int res = 0;
        HDEVINFO hDevInfo;
        SP_DEVINFO_DATA DeviceInfoData = { sizeof(DeviceInfoData) };
    
        // get device class information handle
        hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_ADAPTER, 0, 0, DIGCF_PRESENT  /*| DIGCF_PROFILE*/);
        if (hDevInfo == INVALID_HANDLE_VALUE)
        {
            res = GetLastError();
            return res;
        }
    
        // enumerute device information
        DWORD required_size = 0;
        for (int i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)
        {
            DWORD DataT;
            CM_POWER_DATA cmPowerData = { 0 };
    
            // get device description information
            if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_DEVICE_POWER_DATA, &DataT, (PBYTE)&cmPowerData, sizeof(cmPowerData), &req_bufsize))
            {
                res = GetLastError();
                continue;
            }
    
            printf("PowerState:%d.\n", cmPowerData.PD_MostRecentPowerState);
        }
    
        return 0;
    }

but it doesn't work .

  • Is there reason https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getdevicepowerstate won't work for you? If it doesn't you may need to write a driver to invoke https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/sending-irp-mn-query-power-or-irp-mn-set-power-for-device-power-states – vandench Dec 16 '21 at 22:15
  • Does this give you what you are after? `gcim Win32_PNPEntity | Select name,status,deviceid | ?{$_.name -like "*display*"}` If so, I can post as an answer and expand aliases if needed. If not, maybe you're after DSC info or status or another property of Win32_VideoController? – Dallas Dec 17 '21 at 19:23
  • I should have said that's in PowerShell. If you want to check out the available properties of Win32_VideoController class, you can see what's available with `gcim Win32_VideoController | select -first 1 | select *`, or use `gcim Win32_VideoController | select *` to see properties of each of them. – Dallas Dec 17 '21 at 19:27
  • @Dallas no any of these commands did not give me D0 or D3 state of driver . – Sonali Shrivastava Dec 20 '21 at 12:26
  • @ van can you please share any example where it gives the device driver D0 or D3 state related to this https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/sending-irp-mn-query-power-or-irp-mn-set-power-for-device-power-states – Sonali Shrivastava Dec 20 '21 at 12:28
  • I have confirmed that `gcim Win32_PnPEntity| ?{$_.description -like "*graphics*"}` finds the same three display adapters I see under Display adapters in Device Manager, but it appears neither Win32_PnPEntity, nor Win32_PnPSignedDriver have the Current Power State data you are looking to find. I suspect the only way is to find the right keyname for `(gwmi Win32_PnPEntity| ?{$_.description -like "*graphics*"}).GetDeviceProperties("DEVPKEY_Device_BusReportedDeviceDesc").DeviceProperties.Data` instead of DEVPKEY_Device_BusReportedDeviceDesc, but didn't have much luck finding which property/key. – Dallas Dec 28 '21 at 22:00

0 Answers0