Windows Tip Sheet

Make a New Year's Resolution with Scrnres

Output the screen resolutions for your network's computers with a simple admin tool.

I recently stumbled across a mirror site of Frank Westlake’s utilities page , a site that has more Windows administrative tools than you can shake a stick at. I was actually searching for a way to help a client of mine, who needed to document the screen resolutions his users were using on their computers. After giving up on a VBScript-based solution (I just couldn’t find a way to dig that information out and didn’t have a lot of time to try), I started looking for a tool that would do it for me. Google led me to Frank Westlake’s site, where I felt like I’d hit the utility jackpot.

Screen Resolution Inventory
Okay, I’ll admit up front that what I’m about to do isn’t pretty, but it works. First, the above Web site lists a tool named Scrnres, which displays the resolution of the computer’s screen. You get a simple output, like “1024 x 768” or “800 x 600.” My client needed to find all of those 800 x 600 folks, because a new corporate app requires at least 1024 x 768 resolution.

I could have written a VBScript that ran the Scrnres tool and captured its output, and then logged that information, along with the current user name and computer name, to a text file or database. Looking back, that would have been the way to go. At the time, however, time was of the essence, and I found this tip on JSI FAQ, which offered a quick way out, using the same Scrnres tool.

The tip’s author wrote a batch file:

for /f "Tokens=1,3" %%x in ('scrnres') do (
 set /a ScreenX=%%x
 set /a ScreenY=%%y
)

This sets a ScreenX and ScreenY environment variable containing the current screen resolution. Nifty, because I knew I could write a VBScript that could extract that environment information into variables, and once you’ve got something in a variable you can do anything with it. My client put it all together into a file that logged the information in an Access database. You could take a simpler approach and do something like this:

for /f "Tokens=1,3" %%x in ('scrnres') do (
 set /a ScreenX=%%x
 set /a ScreenY=%%y
)
echo Your resolution is %%x by %%y. If this is ‘800 by 600’, contact the Help Desk immediately for further instructions.
pause

Not pretty, but it gets the message across without too much fuss and bother. Make sure you let the Help Desk know it’s coming (grin).

More Resources:


About the Author

Don Jones has more than a decade of professional experience in the IT industry. He's the author of more than 30 IT books, including Windows PowerShell: TFM; VBScript, WMI, and ADSI Unleashed; Managing Windows with VBScript and WMI; and many more. He's a top-rated and in-demand speaker at conferences such as Microsoft TechEd and TechMentor, and writes the monthly Windows PowerShell column for Microsoft TechNet Magazine. Don is a multiple-year recipient of Microsoft's "Most Valuable Professional" (MVP) Award with a specialization in Windows PowerShell. Don's broad IT experience includes work in the financial, telecommunications, software, manufacturing, consulting, training, and retail industries and he's one of the rare IT professionals who can not only "cross the line" between administration and software development, but also between IT workers and IT management.

Reader Comments:

Mon, Apr 25, 2005 Anonymous Anonymous

Bad, bad article. I just spent 15 minutes, using MSDN and figured this out. The ScriptoMatic script uses a class that is no longer available in Windows XP. Here is what I did:

strComputer = inputBox("Please enter the computer name" , "Computer Name")

if strcomputer = "" then


strComputer = "."

end if

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

set colItems = ObjWMIService.ExecQuery("Select * from Win32_VideoController")
for each i in colItems
wscript.echo "The current screen resolution on " & strComputer & _
" is " & i.CurrentHorizontalResolution & " x " & _
i.CurrentVerticalResolution
Next


This is for a single computer. Just make an array if you need to do it for a collection of computers. This isn't hard stuff man!

Wed, Dec 29, 2004 Marcus TN

For a scripting site, I would think that you would tap the technology found in WMI to get this information. I have a hardware inventory script that enumerates all computer in my AD domain and pulls dang near everything about them (including screen resolution) and writes it to a SQL database for querying.

Wed, Dec 29, 2004 Kaplaa NC

Lame article. I wrote this in less than 5 minutes. You really should get a copy of Scriptomatic. It makes writing these scripts easy.
=============


On Error Resume Next

If WScript.Arguments.Count = 1 Then
strComputer = WScript.Arguments(0)
Else
Dim WshShell
Set wshShell = WScript.CreateObject("WScript.Shell")
strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
strComputer = InputBox("Check Screen Resolution of what PC","System Name",strComputer)
End If

If strcomputer = "" Then WScript.Quit
strComputer = UCase(strComputer)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select pelsHeight, pelsWidth from Win32_DisplayConfiguration",,48)
For Each objItem in colItems
MsgBox "Screen Res: " & objItem.PelsWidth & " x " & objItem.PelsHeight, vbinformation & vbokonly,strcomputer
Next

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above