WMI Query of Screen Resolution

(imported topic written by SystemAdmin)

We are preparing to deploy a new large information system. before we roll it out, I have been asked to gather an inventory that includes Monitor size. I can’t find “Monitor Size” (they want it in Inches) but I have found a WMI query to let me gather the Screen Width and Height.

if (exists wmi) then (string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) else (“N/A”)
if (exists wmi) then (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi) else (“N/A”)

What I would LIKE to do is gather this into a Retrieved Property listing WidthxHeight, but I have not been able to figure it out yet. Each attempt comes back as “A singlular expression is required.”

I tried

if (exists wmi) then ((string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) + “x” + (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi)) else (“N/A”)

Can someone one help me resolve this?

(imported comment written by SystemAdmin)

your returning a plural string ( 2 values )

Q: (if (exists wmi) then (string values of selects “ScreenWidth from Win32_DesktopMonitor” of wmi) as string else (“N/A”))

A: 1680

A: 1680

I: plural string

Q: ((if (exists wmi) then (string values of selects “ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))as string)

A: 1050

A: 1050

I: plural string

(

if (exists wmi) then (string value of select 
"ScreenWidth from Win32_DesktopMonitor" of wmi) as string 

else (
"N/A"))  & 
"x" & (

if (exists wmi) then (string value of select 
"ScreenHeight from Win32_DesktopMonitor" of wmi)as string 

else (
"N/A"))

(imported comment written by SystemAdmin)

DOH!!!

Thank you!

(imported comment written by SystemAdmin)

I’m getting an odd response to the WMI Query on some of the computers.

q: (if (exists wmi) then (string value of select “ScreenWidth from Win32_DesktopMonitor” of wmi) as string else (“N/A”)) & “x” & (if (exists wmi) then (string value of select “ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))
A: 1024x768
E: Singular expression refers to non-unique object.

Most of the systems return an expected value, and even on an erroring machine, I get the response above. I broke each of the seperate WMI queries out and each of them returns the an Error condition along with the correct resolution.

Most perplexing. Anyone have any thoughts?

(imported comment written by SystemAdmin)

When I view the properties for the Erroring computers, it shows me the resolution, but in the column view all I see is .

Monitor Resolution 1024x768
Singular expression refers to non-unique object.

(imported comment written by jeremylam)

I think the computers that are erroring have two monitors, so each wmi query

string values of select 
"ScreenWidth from Win32_DesktopMonitor" of wmi

returns two strings, and two strings cannot be appended to two other strings (relevance doesn’t try to correlate them).

You have to return all the results in one wmi query; I played around with it for a bit and got this:

q: (string value of property 
"ScreenHeight" of it & 
"x" & string value of property 
"ScreenWidth" of it) of select objects 
"ScreenWidth, ScreenHeight from Win32_DesktopMonitor" of wmi A: 1200x1600 A: 1200x1600 I: plural string

Which works on both my single monitor computer and dual monitor computer.

Hope this helps.

(imported comment written by SystemAdmin)

(unique values of (string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)

Q: unique values of ((string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)

A: 1680x1050

(imported comment written by SystemAdmin)

Still having trouble with this.

q: (if (exists wmi) then ((string value of property “ScreenHeight” of it & “x” & string value of property “ScreenWidth” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)as string else (“N/A”))

A: 768x1024

E: Singular expression refers to nonexistent object.

This is from a computer with a single monitor. I tried Mark’s code and get an error …

q: unique values of ((string value of property “ScreenWidth” of it & “x” & string value of property “ScreenHeight” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi)

E: Singular expression refers to nonexistent object.

Jeremy’s code …

q: (string value of property “ScreenHeight” of it & “x” & string value of property “ScreenWidth” of it) of select objects “ScreenWidth, ScreenHeight from Win32_DesktopMonitor” of wmi

A: 768x1024

E: Singular expression refers to nonexistent object.

Anyone have any other suggestions? I’d be happy if I could just get ONE screen resolution since there are only a few here that have different resolutions, usually laptops where users have an external monitor they attach at their desks via docking stations.

(imported comment written by SystemAdmin)

I’ve also found the screen resolution listed in the Registry under the following key …

HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\VIDEO{44C24229-9918-4E49-BD60-82DF1516096A}\0000

DefaultSettings.XResolution REG_DWORD = HEX 400 = DEC 1024

DefaultSettings.YResolution REG_DWORD = HEX 300 = DEC 768

(imported comment written by SystemAdmin)

I ended up using

if (exists wmi AND exists select 
"VideoModeDescription from Win32_VideoController" whose (type of it = 8) of wmi) then (preceding text of last 
" x" of (string values of selects 
"VideoModeDescription from Win32_VideoController" whose (type of it = 8) of wmi)) 

else (
"N/A")

I found it in an Analysis already in my deployment.

Seems to work very well. There are still some systems that report , but we have such an eclectic mix of systems I’m not surprise or concerned. I’m happy to have numbers for the vast majority of the systems.