Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2012-08-30
6
Medium Priority
?
1,104 Views
Last Modified: 2014-05-25
Hello everyone,

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 :

* 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 ). 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.
0
Comment
Question by:limnath
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38351255
0
 

Author Comment

by:limnath
ID: 38352021
Thanks for the link you provided.

I looked at it. However the link mentions nothing about getting Display monitor information. It talks about getting  CPU, the RAM, the hard disk, Windows version, which I already know how to do without problems.

I need a solution to my problem at hand, which is to get Display properties of Multiple Monitors Attached to my Computer.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 38352036
download the demo, it has the info of the screens. look at the image, you see 2 monitor.
0
 

Accepted Solution

by:
limnath earned 0 total points
ID: 38369057
I believe I am beginning to understand the problem...


There is a difference between a logged on user and a Windows service. When you run a Windows service, it runs in a different desktop than a logged in User. In fact, each logged in user runs in its own desktop.

As such, the reason that you only get one monitor returned when running as a windows service is because that desktop (i.e. the windows service desktop(0) ) has a default non-visible monitor assigned to it.

 The first logged on user gets a different desktop(1) and might have two monitors configured and the next user (running in desktop(2)) might not have the "extend desktop to other monitors" setting checked so it only sees one monitor.

So monitor count would be something like:
Service 1
User1 2
User2 1

If you run your monitor tool under the service, it will run under the context of the service account and therefore it returns 1 monitor. Your service code could run the tool (Process.Start or runas) under a different user account, but then the service would need the login account credentials of the user you wish to run under.

So I believe there is no easy way to solve this problem and unless someone comes up with a better solution, I would have to conclude ( at least at this point in time ) that we CANNOT use the Windows Service approach to solve this problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I read that Microsoft has analysed statistics for their security intelligence report. It revealed: still, the clear majority of windows users do their daily work as administrator. An administrative account is a burden, security-wise. My ar…
The article covers five tools all IT professionals should know about, as they up productivity by a great deal!
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question