2

I'm trying to find/write a script (existing script is a batch file, although if VBS I could always call it within batch file) that can detect if the current screen resolution is a widescreen format, so that I can copy the appropriate background image to the machine. I've only found a couple posts with the same code, and as one reply said that you can always just set the image to be stretched. But that would mean that the image could be distorted (as others have said as well).

I found the following VBScript from this post, although it only seems to work on Windows XP (although I haven't tried Windows 7 32-bit). In Windows 7 64 it just echos the asterick.

Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
 Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
 For Each objItem in colItems
 intHorizontal = objItem.ScreenWidth
 intVertical = objItem.ScreenHeight
 Next 

msgbox intHorizontal & " * " & intVertical 

But even if I could get this script to work, I would still have to have multiple IF's to match the Horizontal & Vertical to a list of widescreen resolutions. Unless there's a math equation that I can use (which I'm sure there is). But regardless, I need a script that will work for both XP and 7 (32 & 64), or if need be, two scripts for each OS or architecture.

Thanks in advance,

Brian

5
  • OK, I found my math equation. If W/H=1.33 (or 1.25 for 5:4 ratio) then aspect ratio is 4:3, otherwise it's widescreen (1.6 through 1.78). So now I just have to get a script that works for all OS's & architectures, as well as work this formula into it.
    – Brian
    Apr 6, 2013 at 19:52
  • 2
    OK, so this works fine: If intHorizontal/IntVertical <= 1.334 then Aspect = "4:3" WScript.Echo Aspect Else Aspect = "Widescreen" WScript.Echo Aspect End if And I've test the original code to enumerate the resolution on XP and Win7 (32 and 64) virtual machines, and they both work fine. But on my host machine (7/64) it just echo's back the "*", with no resolution. Only thing I can see that might be doing it is I do have 2 monitors. I have checked and WMI is running.
    – Brian
    Apr 6, 2013 at 22:57
  • 1
    Wow, had I known I was going to find the answer so soon, I wouldn't have bothered posting this. This WMI seems to work beautifully: Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController",,48) For Each objItem in colItems intHorizontal = objItem.CurrentHorizontalResolution intVertical = objItem.CurrentVerticalResolution Next
    – Brian
    Apr 7, 2013 at 1:00
  • Can you post a complete answer and accept it? Mar 12, 2014 at 13:38
  • I used this solution with Windows 10 and it worked well.
    – Lou
    Jan 15, 2021 at 19:00

1 Answer 1

0

So sorry for the delay, I'm not regularly on here. My last comment is the answer/solution that worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.