{"id":69343,"date":"2005-07-21T20:43:00","date_gmt":"2005-07-21T20:43:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/07\/21\/how-can-i-determine-the-current-screen-resolution-being-used-on-a-computer\/"},"modified":"2005-07-21T20:43:00","modified_gmt":"2005-07-21T20:43:00","slug":"how-can-i-determine-the-current-screen-resolution-being-used-on-a-computer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-the-current-screen-resolution-being-used-on-a-computer\/","title":{"rendered":"How Can I Determine the Current Screen Resolution Being Used on a Computer?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I determine the current screen resolution being used on a computer? You know, things like 1600&#215;1200 resolution, 16-bit color, that kind of information.<BR><BR>&#8212; FE<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>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 <I>didn\u2019t<\/I> ask? For example, suppose you said, \u201cMom, can I go over to Billy\u2019s?\u201d Inevitably she would answer, \u201cNo, you <I>cannot<\/I> go down to the lake without an adult present. But you can go over to Billy\u2019s as long as you two stay away from the lake.\u201d <\/P>\n<P>Remember how much fun that was? Well, in case you\u2019ve forgotten, we\u2019ll refresh your memory: \u201cNo, you <I>cannot<\/I> 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.\u201d<\/P>\n<P>Oh, and stay away from the lake; after all, you have work to do!<\/P>\n<P>We know you didn\u2019t ask about changing screen resolution using a script, but we felt we\u2019d better mention that lest we get millions of emails asking that very question. (We\u2019ll 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 \u201cfor worse\u201d) there\u2019s no built-in way to change the screen resolution using a script. Sorry.<\/P>\n<P>But if all you want to do is retrieve the current resolution settings the news is a bit better:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;<\/p>\n<p>Set objWMIService = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\cimv2&#8221;)<\/p>\n<p>Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_DisplayConfiguration&#8221;)<\/p>\n<p>For Each objItem in colItems\n    Wscript.Echo &#8220;Name: &#8221; &amp; objItem.DeviceName\n    Wscript.Echo &#8220;Color depth: &#8221; &amp; objItem.BitsPerPel\n    Wscript.Echo &#8220;Horizontal resolution: &#8221; &amp; objItem.PelsWidth\n    Wscript.Echo &#8220;Vertical resolution: &#8221; &amp; objItem.PelsHeight\n    Wscript.Echo\nNext\n<\/PRE>\n<P>Of <I>course<\/I> it\u2019s 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 <B>Win32_DisplayConfiguration<\/B> class:<\/P><PRE class=\"codeSample\">Set colItems = objWMIService.ExecQuery _\n    (&#8220;Select * From Win32_DisplayConfiguration&#8221;)\n<\/PRE>\n<P>We then echo back the values of various properties, including <B>DeviceName<\/B>, <B>BitsPerPel<\/B> (the color depth), <B>PelsWidth <\/B>(the horizontal resolution), and <B>PelsHeight<\/B> (the vertical resolution). In other words, property values similar to this:<\/P><PRE class=\"codeSample\">Name: RADEON IGP 345M\nColor depth: 32\nHorizontal resolution: 1024\nVertical resolution: 768\n<\/PRE>\n<TABLE id=\"EAE\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Scripting Guys Trivia<\/B>. The term <I>pels<\/I> is short for picture elements, more commonly referred to as pixels. Hey, when you\u2019re a Scripting Guy you\u2019re <I>supposed<\/I> to know stuff like that!<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>So there you have it: a way to retrieve the current screen resolution on a computer. We\u2019re glad we could help, but this does <I>not<\/I> mean you can go anywhere near that lake! (Yes, we <I>are<\/I> mean, aren\u2019t we? But you\u2019ll thank us for that someday.)<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I determine the current screen resolution being used on a computer? You know, things like 1600&#215;1200 resolution, 16-bit color, that kind of information.&#8212; FE 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\u2019t [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[34,3,5,70],"class_list":["post-69343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-hardware","tag-scripting-guy","tag-vbscript","tag-video-and-display"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I determine the current screen resolution being used on a computer? You know, things like 1600&#215;1200 resolution, 16-bit color, that kind of information.&#8212; FE 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\u2019t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=69343"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=69343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}