views:

90

answers:

2

I'm curious as to how WMI works. Particularly, I am currently using WMI to query for the physical monitors via "Select * from Win32_DesktopMonitor" as it has consistently given me the correct result across multiple platforms since I want to know the count of physical monitors and not virtual monitors returned by functions like GetSystemMetrics and EnumDisplays. I have also explored the SetupAPI, which inspects the registry like the Device Manager, but can incorrectly return phantom monitors in pre Vista version of Windows.

I have tried to trace the API calls and watch events with procmon.exe made by wbemtest.exe and my own executables making queries, but have not found much.

Any insight to the inner workings of WMI, more in depth tracing of API calls, or reliable ways to count monitors would be appreciated.

Minor Notes: Working with C++

+1  A: 

It talks to the device drivers, nobody knows better what hardware is available. You can read more about in this Microsoft article.

Hans Passant
+1  A: 

It is also worth checking the MappingStrings qualifier (if present) for the class properties you are interested in. For Win32_DesktopMonitor, for example:

DeviceId:
Win32API|Windows GDI|HMONITOR

InstallDate:
MIF.DMTF|ComponentID|001.5

MonitorManufacturer:
Win32Registry

MonitorType:
Win32Registry

PixelsPerXLogicalInch:
Win32API|Device Context Functions|GetDeviceCaps

Uros Calakovic
Ah, that's very informative, thanks!
chromic