-2

i would like to check every devices (like wifi or bluetooth) status,knowing they are working fine or not or they lost when i do reboot stress test, how can i get the devices status(like the property of device in devices management)?does the windows has API to get that?

1 Answers1

0

for get get the devices status you need call CM_Get_DevNode_Status

for get DEVINST dnDevInst you can enumerate all devices with CM_Get_Device_ID_ListW + CM_Locate_DevNode or alternative use CM_Locate_DevNode + CM_Get_Child + CM_Get_Sibling

for example:

void enumDN(DEVINST dnDevInst)
{
    union {
        PVOID buf;
        PBYTE pb;
        PWSTR sz;
    };

    ULONG cb = 0, rcb = 256;

    static volatile UCHAR guz;

    PVOID stack = alloca(guz);

    WCHAR Name[MAX_DEVICE_ID_LEN];

    CONFIGRET err;

    if (CM_Get_Device_ID(dnDevInst, Name, RTL_NUMBER_OF(Name), 0) == CR_SUCCESS)
    {
        DEVPROPTYPE PropertyType;
        ULONG Status, ulProblemNumber;

        if (CM_Get_DevInst_Status(&Status, &ulProblemNumber, dnDevInst, 0) == CR_SUCCESS)
        {
            PWSTR FriendlyName = NULL;
            do 
            {
                if (cb < rcb)
                {
                    rcb = cb = RtlPointerToOffset(buf = alloca(rcb - cb), stack);
                }

                if ((err = CM_Get_DevNode_PropertyW(dnDevInst, &DEVPKEY_Device_FriendlyName, 
                    &PropertyType, pb, &rcb, 0)) == CR_SUCCESS)
                {
                    if (PropertyType == DEVPROP_TYPE_STRING)
                    {
                        FriendlyName = sz;
                    }
                }

            } while (err == CR_BUFFER_SMALL);

            DbgPrint("%08x %S %S\n", Status, Name, FriendlyName);
        }
    }

    if ((err = CM_Get_Child(&dnDevInst, dnDevInst, 0)) == CR_SUCCESS)
    {
        do 
        {
            enumDN(dnDevInst);

        } while ((err = CM_Get_Sibling(&dnDevInst, dnDevInst, 0)) == CR_SUCCESS);
    }
}

void enumDN()
{
    DEVINST dnDevInst;
    if (CM_Locate_DevInstW(&dnDevInst, NULL, 0) == CR_SUCCESS)
    {
        enumDN(dnDevInst);
    }
}
RbMm
  • 31,280
  • 3
  • 35
  • 56