WMI C# Question: How to get Display properties of Multiple Monitors Attached to my Computer
Posted on 2012-08-30
I have a project that requires me to gather inventory data for my computer. I am having problems trying to get the properties of the monitors attached to my computer.
I have one computer that can potentially use a max of 4 monitors, wherein I have a primary monitor and 3 other potential monitors which act as extension screens when I move my mouse to them ( depending on whether they are connected or not ).
I need to grab the following information from each monitor :
* Horizontal and Vertical resolution,
* Whether or not the monitor is the primary one ( a true or false value will suffice ).
I tried using the WMI, Win32_DesktopMonitor class but it is only giving me ONE monitor's results ( the primary monitor ). It does not seem to grab data for other attached monitors other than the primary one.
I then tried using the Win32_PnPEntity class.
This works, and gives me the number of monitors attached to my computer, but it only gives me Name and DeviceId ( no horizontal and vertical resolution information in this class ).
I then tried the Screen class (using the System.Windows.Forms.Screen), however the result is erratic. If I ran the program as a pure console application, it works and gives me the right number of monitors attached to my computer, when I ran the same program as a windows service, it does not. It only gives me ONE ( the primary monitor ).
Does anyone know of a Class provided by .NET 4 that will help me gather the information I need?
I am using the following environment:
1) .NET 4
2) Visual Studio 2010
3) C# programming language
4) Windows Service Application
Any suggestions and advise will be highly appreciated. If you need to look at the code I used to run it, I will be glad to post it too. If requested.
Thank you very much everyone for reading this and for any help or guidance.