WMI Question: How to get Display properties of Multiple Monitors Attached to my Computer

Aug 29 2012 5:44 PM
Hello everyone,
I have a C# project written in .NET 4 environment ( I am using Visual Studio 2010 ) 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 to run this application as a Windows Service.

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 pointer to them ( depending on whether they are connected or not ).
I need to grab the following information from each monitor :

* DeviceId, 

* Name, 

* 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 ).

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 .NET Framework 4 and building my application as a Windows Service application.
Any suggestions and advise will be highly appreciated.

Answers (1)