问题
I am using WMI Win32_MonitorDesktop
to get all the monitors information on the system.
However it only returns one. I have tried it on several computers, and they definitely have multiple monitors on them, connected and working.
ManagementObjectSearcher monitorObjectSearch = new ManagementObjectSearcher("SELECT * FROM Win32_DesktopMonitor");
foreach (ManagementObject monitor in monitorObjectSearch.Get())
{
Debug.WriteLine(monitor["Description"]);
}
Does anyone know why i'm only getting 1 monitor returned?
Also if I assign the return value of monitorObjectSearch.Get() to a variable, I am unable to evaluate the Count property in the immediate window as the function always times out.
回答1:
It could be that the monitors are set up in a horizontal span mode (NV and ATI cards) which effectively make multiple monitor setups into one big monitor? Otherwise, I'll continue to have a think..
Also the MSDN quite specifically states that if this WMI call is used with anything pre-vista it will yield inaccurate results!?
回答2:
I tried to resolve this problem using WMI on many systems (from WinXP-SP3 up to Win10), and I got different results on different machines. There are two tables, where current monitor setting can be stored. First is Win32_DesktopMonitor in cimv2 namespace, second is WMIMonitorID in wmi namespace. If one of them has only one record (in multi display setting), then second will have all of entries.
Then to get driver name of monitor, one should find devices with PnPDeviceID found in records from those tables in Win32_PnPEntity table, in cimv2 namespace. You can check sample solution here.
回答3:
I use the same code from wmi (win32_Desktopmonitor) on a windows 7 machine. It doen't work there as well, in the sense that only 1 monitor is returned, where there are really two.
Also Screen.Allscreens.Length, only returns 1 monitor. The only way to get the system to return 2 monitors, is to extend the desktop to the two monitors, but that's not what most people do.
回答4:
This certainly does not answer your actual question but most reliable way of figuring out monitor information is to read following registry:
"SYSTEM\CurrentControlSet\Enum\DISPLAY\"
under HKEY_LOCAL_MACHINE
来源:https://stackoverflow.com/questions/1422065/wmi-get-all-monitors-not-returning-all-monitors