Using device manager a user can explicitly enable/disable a device, as can be seen in the following image.
For a given device I want to know if it's currently in a user disabled/enabled state.
I have tried the following approaches
CM_Get_DevNode_Status(&status, &problem, data.DevInst, 0);
I was hoping that presence ofDN_STARTED
, orDN_DRIVER_LOADED
would tell me that. But these can be zero even when a driver is being loaded/unloaded by the OS, when the device connects/disconnects. For example, a device which is enabled, and for which driver is loaded.DN_STARTED
will be1
, but when we disconnect device it is set to zero before the device's entry is removed from device manager.SetupDiGetDeviceRegistryProperty(..., SPDRP_INSTALL_STATE, ...)
I though a state ofCM_INSTALL_STATE_INSTALLED
should mean that the device is enabled. But the function returns this state even for disabled devices.Using WMI I was able to get the required information, but I used wmi in PowerShell. I do not want to use wmi, as it is quite difficult to implement in native c++. I used the following query.
Select Name, Availability, ConfigManagerErrorCode, ConfigManagerUserConfig from Win32_PnPEntity where Name = 'NVIDIA Quadro M1000M'
ConfigManagerErrorCode in above query, if set to 22, means that device has been disabled, 21 means that windows is removing the device
I am looking for a non wmi solution.