How Can I Determine the Current Screen Resolution Being Used on a Computer?

How Can I Determine the Current Screen Resolution Being Used on a Computer?

  • Comments 2
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I determine the current screen resolution being used on a computer? You know, things like 1600x1200 resolution, 16-bit color, that kind of information.

-- FE

SpacerHey, Scripting Guy! AnswerScript Center

Hey, FE. Remember when you were a kid and your mom would have that annoying habit of beginning a discussion by answering the question you didn’t ask? For example, suppose you said, “Mom, can I go over to Billy’s?” Inevitably she would answer, “No, you cannot go down to the lake without an adult present. But you can go over to Billy’s as long as you two stay away from the lake.”

Remember how much fun that was? Well, in case you’ve forgotten, we’ll refresh your memory: “No, you cannot use a script to change the screen resolution on a computer. You can use a script to retrieve information about the current screen resolution, but that information is read-only.”

Oh, and stay away from the lake; after all, you have work to do!

We know you didn’t ask about changing screen resolution using a script, but we felt we’d better mention that lest we get millions of emails asking that very question. (We’ll probably still get millions of emails asking that very question, but at least we tried.) For better or worse (and yes, we agree that this qualifies as “for worse”) there’s no built-in way to change the screen resolution using a script. Sorry.

But if all you want to do is retrieve the current resolution settings the news is a bit better:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DisplayConfiguration")

For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.DeviceName
    Wscript.Echo "Color depth: " & objItem.BitsPerPel
    Wscript.Echo "Horizontal resolution: " & objItem.PelsWidth
    Wscript.Echo "Vertical resolution: " & objItem.PelsHeight
    Wscript.Echo
Next

Of course it’s a simple little script; the Scripting Guys are simple little guys! All we do is connect to the WMI service and then use this query to retrieve all the instances of the Win32_DisplayConfiguration class:

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_DisplayConfiguration")

We then echo back the values of various properties, including DeviceName, BitsPerPel (the color depth), PelsWidth (the horizontal resolution), and PelsHeight (the vertical resolution). In other words, property values similar to this:

Name: RADEON IGP 345M
Color depth: 32
Horizontal resolution: 1024
Vertical resolution: 768

Scripting Guys Trivia. The term pels is short for picture elements, more commonly referred to as pixels. Hey, when you’re a Scripting Guy you’re supposed to know stuff like that!

So there you have it: a way to retrieve the current screen resolution on a computer. We’re glad we could help, but this does not mean you can go anywhere near that lake! (Yes, we are mean, aren’t we? But you’ll thank us for that someday.)

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • just for the record, i cannot find (on windows 7 and XP) another resolution than 1024x780, with dual displays, with only one display, changing resolutions, on about 100 computers... the DeviceName and DriverVersion is perfect, superb... but the rest is a LIE :(

    this example is perfect, but pelsheight and pelswidth are always 1024,780... i hope it worked ok on 2005...

    as I see it, this wmi view is as useful as Win32_ScheduledJob, it feels like windows grew but wmi not, just like a notepad :(

  • The Win32_displayConfiguration WMI class no longer works beginning with Windows Vista. This is detailed on MSDN msdn.microsoft.com/.../aa394137(v=vs.85).aspx Instead, use the Win32_VideoController.

    Using Windows PowerShell the command looks like this: gwmi win32_videocontroller and I just checked it, and it works on my laptop.