locked
Pull multiple monitor resolutions with VB Script RRS feed

  • Question

  • Hey guys,

    I've just started getting into the more (what I consider)  complex elements of IT, and I am currently trying to configure BGinfo to work for some computers we use at work.

    I am trying to get the utility to display the resolutions of multiple monitors (these computer will have 2-3 monitors).

    It should look something like:

    Monitor 1: 1920 * 1080

    Monitor 2: 1920 * 1080

    The BGInfo utility runs a VBScript and this is what I have written so far (I have only just started learning Visual Basic at uni so some posts have PowerShell scripts which appear similar but I can't work them out.

    The code I have so far (which only displays 1 display even though I currently only have 2)

    'Gets details of monitors and returns them '1/09/13 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colVidControllers = objWMIService.ExecQuery("Select * FROM Win32_VideoController") iCount=1 For Each objVidController in colVidControllers sMonitors = "Monitor "& iCount &": "& objVidController.CurrentHorizontalResolution &" * " & objVidController.CurrentVerticalResolution &" @ " & objVidController.CurrentrefreshRate &"hz" &vbcrlf &" " icount = icount+1 Next wscript.echo sMonitors

    'This will not be a message once I have confirmed it works

    I can't post links because my account isn't verrified yet. But if you search "fc2479b5-6cc1-490d-a6a3-d18a2e233655" you can see the answer  that I have mainly used to build this code, and I just don't know why it isn't looping for the 2nd monitor.

    Hopefully someone can shed some light on this.

    Regards

    Cal

    • Moved by Bill_Stewart Sunday, December 29, 2013 11:37 PM Abandoned
    Sunday, September 1, 2013 12:40 PM

All replies

  • Change to this:

    For Each objVidController in colVidControllers 
            WScript.Echo "Monitor " & iCount &": "& objVidController.CurrentHorizontalResolution  &" * " & objVidController.CurrentVerticalResolution &" @ " & objVidController.CurrentrefreshRate &"hz" &vbcrlf &"	"
    	icount = icount+1
    Next 

     

    ¯\_(ツ)_/¯



    • Edited by jrv Sunday, September 1, 2013 5:26 PM
    Sunday, September 1, 2013 5:07 PM
  • This may be even easier to understand

    Set monitors = GetObject("winmgmts:").ExecQuery("Select * FROM Win32_VideoController")
    iCount=1    
    For Each monitor in monitors 
        With monitor
            hz = .CurrentHorizontalResolution
            vt = .CurrentVerticalResolution
            rr =.CurrentrefreshRate
        End With
        WScript.Echo "Monitor " & iCount & ": "& hz & "*" & vt & "@" & rr
    	icount = icount+1
    Next 
    

    Be sure to always allow spaces around the & operator 


    ¯\_(ツ)_/¯

    Sunday, September 1, 2013 5:27 PM