Win32_DesktopMonitor was deprecated. It also will not tell you accurate information about the displays attached. You may not even get any information at all. On my machine right now, I've got a laptop built-in display and two external monitors. There's only a single instance of Win32_DesktopMonitor being returned and it just lists generic information. There's nothing on the manufacturer or model of the monitors, or anything else that would be useful.
About the only class that returns anything accurate is the Win32_VideoController class, but it won't return any monitor information.
About the only EASILY ACCESSIBLE place I've found that can get you information on the monitors is looking in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY. You're looking for the EDID data, which you're going to have to decode to get the vendor/model information.
Be warned. Everything under this key will give you the EDID data for EVERY monitor that has ever been attached to the system. It does NOT remove the data for monitors that are no longer attached!
The hard way to do it would be to call the Windows EnumDisplayDevices function in user32.dll.
Start by using the debugger: put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why. You need to find out which argument is out of range, and what the valid range is - until you have that, you can't start looking at why it's out of range!
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
you fooled yourself by using a lot of redundant brackets. The compiler doesn't mind, but you lost track of what is inside the inner for loop and what isn't.
Once you fix the problem, you'll find out you're not there yet, as Write() or WriteLine() will use whatever number of positions is required to represent the number, so the table may well be badly aligned. If so, start looking at some overloads of int.ToString().
In your variable declarations, change "ManagementQuery" to "ObjectQuery". You cannot declare an instance variable as an abstract class type and then start calling methods and setting properties on it as the abstract class won't have implementations of those properties and methods.
Hi Dave and Richard, thank you for checking my code.
Richard yes that is error I’m getting and thank you trying Dave.
I’m stuck and will have to check Microsoft links tomorrow at work like I said it is my first time and I’m stuck and don’t understand.
Dave since you tried and saw the errors would you be kind to highlight where I’m going wrong so that I can learn from please but if you think it’s better to read the links then I would do that but if I’m not mistaken I got some of the code from Microsoft to understand and I tried but without success.