+ Post New Thread
Results 1 to 14 of 14
Scripts Thread, VBS detect Screen Resolution in Coding and Web Development; Any ideas on how to achieve this? Google isn't helping much, and I've not tracked down a single script that ...
  1. #1

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    143

    VBS detect Screen Resolution

    Any ideas on how to achieve this?

    Google isn't helping much, and I've not tracked down a single script that works. Is it even possible?

    What we want to do is host the background for student desktops locally on each machine to save on network traffic, so I want to write a VBS script to copy down the correct version from the server the first time the workstation is started up after imaging, but to copy down a different version depending on screen resolution as we have a nice wallpaper designed by one of my techs that works well with BG info, but it needs to be displayed at the correct resolution to work.

    Can anyone help!

    Thanks in anticipation,

    Mike.

  2. #2

    Michael's Avatar
    Join Date
    Dec 2005
    Location
    Birmingham
    Posts
    8,941
    Thank Post
    232
    Thanked 1,510 Times in 1,206 Posts
    Rep Power
    328
    Within BGInfo you have the option to stretch an image, so it'll cover any resolution. Double click BGInfo.exe, navigate to: Background, specify the wallpaper, then specify the Wallpaper Position as 'Stretch' from the drop down menu.

  3. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,208
    Thank Post
    2,763
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    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

  4. 2 Thanks to mac_shinobi:

    Ignatius (17th July 2009), maniac (17th July 2009)

  5. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    Quote Originally Posted by Michael View Post
    Within BGInfo you have the option to stretch an image, so it'll cover any resolution. Double click BGInfo.exe, navigate to: Background, specify the wallpaper, then specify the Wallpaper Position as 'Stretch' from the drop down menu.
    Yes, but that kind of messes things up when someone's made the effort to be creative and make something that will look wrong when it's stretched :-)

  6. #5

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    143
    Thanks for that mac_shinobi

    Just out of interest where did you find it or did you just happen to know the code? I've searched for ages and the only codes I found were for ASP web pages, or used really complex methods to grab the data.

    And yes srochford you're right, stretching it is not an option for this background - we've got pre-defined boxes on one side of it which BG info will populate with info for us (Specifically logged on username and logon time) and these need to be the same size and in exactly the same place on each background for BGinfo to put the text in the correct place. Also stretching it just distorts it all and makes text look naff, and I want our system to be top notch in all respects.

    Thanks all

    Maniac.

  7. #6


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,657
    Thank Post
    350
    Thanked 789 Times in 710 Posts
    Rep Power
    344
    Found it here

  8. #7

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    143
    Quote Originally Posted by kmount View Post
    Found it here
    I was looking at that very site earlier, guess it depends exactly what you type in the search box as to what comes up - Nonsense in, Nonsense out.

    Mike.

  9. #8

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,208
    Thank Post
    2,763
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    It's called WMI - and I found it there and a few other places.

    There is another way by using internet explorer to do it for you but did not have much time to do it that way so just posted the wmi way which is a lot neater and better solution

    see below ( from one of my EE posts ) obviously this is more for setting the resolution then getting ( aside from the script below using internet explorer )

    http://www.experts-exchange.com/Prog..._21479950.html

    This is what I have found :

    ==================================

    How do I change screen resolution or wallpaper?
    Screen resolution cannot be changed from WSH. Here are some workarounds, almost entirely taken from Torgeir Bakken's responses on this topic.

    Use Multires (which is free) <-- as mentioned below you can use the multires exe to apply screen resolutions etc
    http://www.entechtaiwan.com/util/multires.shtm

    Here's a reference to doing it via Java
    http://home.istar.ca/~neutron/JDirect/DisplaySettings/

    It should also be possible to do this using the ChangeDisplaySettings API, but you would need to write a component to access it.

    Win9x clients running the QuickRes powertoy can run a shell command like this:
    RunDLL deskcp16.dll,QUICKRES_RUNDLLENTRY 1280x1024x24

    FINDING the screen resolution is possible, albeit not "natively" - here's a quick script that will give you current screen resolution via Internet Explorer:

    Code:
    with createobject("internetexplorer.application")
        .navigate "about:blank"
        with .document.parentWindow.screen
          msgbox .width & " by " & .height
        end with
      end with
    Wallpaper can be modified in the registry; unfortunately, changes don't take place until you refresh, either by logoff/logon or by manually refreshing the desktop.
    The relevant registry key is HKCU\Control Panel\Desktop\Wallpaper. To see an example script of copying wallpaper and changing it, see:

    http://groups.google.com/groups?selm...%40tkmsftngp05

    There is a rundll32 command to update the HKCU section of the registry as well which will update it without logging off and back on

    ===================================

    I got that from this site :

    http://www.mvps.org/scripting/faq/wshfaq.htm
    Last edited by mac_shinobi; 17th July 2009 at 06:00 PM.

  10. #9


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,207
    Thank Post
    218
    Thanked 812 Times in 694 Posts
    Rep Power
    274
    if you just want to set it and forget it i use a script on the pcs ou that on bootup copy's a batch file to c:\documents and settings\all users\start menu\programs\startup

    use qures.exe (i copy to c:\windows so its pathed) then batch file in all user\startup is

    Code:
    qres /x:1440 /y:900 /c:16
    just change the numbers as appropriate (i use 16 as some sherston software cant hack 32 bit colour)

  11. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,208
    Thank Post
    2,763
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by sted View Post
    if you just want to set it and forget it i use a script on the pcs ou that on bootup copy's a batch file to c:\documents and settings\all users\start menu\programs\startup

    use qures.exe (i copy to c:\windows so its pathed) then batch file in all user\startup is

    Code:
    qres /x:1440 /y:900 /c:16
    just change the numbers as appropriate (i use 16 as some sherston software cant hack 32 bit colour)
    you can do that with multi res as well and for multiple monitors

  12. #11

    Join Date
    May 2009
    Location
    UK
    Posts
    291
    Thank Post
    64
    Thanked 21 Times in 20 Posts
    Rep Power
    14
    Grrr! I've also been searching for this to incorporate into BGInfo for a while. Thanks mac_shinobi for the solution.

  13. #12

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    If the question is "how do I use a script to find out XXX about my PC" then the answer is almost always "use WMI" :-)

    Given that little acronym, googling just becomes so much easier!

    A really good way to find out what you can do with WMI is to use the Microsoft Scriptomatic tool

  14. #13
    kearton's Avatar
    Join Date
    May 2007
    Location
    Yorkshire, via NZ ;)
    Posts
    803
    Thank Post
    119
    Thanked 78 Times in 68 Posts
    Rep Power
    40
    Quote Originally Posted by srochford View Post
    Yes, but that kind of messes things up when someone's made the effort to be creative and make something that will look wrong when it's stretched :-)
    I wish someone (else, my comments go in one ear and out the other) would tell that to one of the IT staff here. He hasn't updated his video driver. I know I'm a pedant, but I just can't stand seeing things displayed in 4:3 on a widescreen monitor. The entire thing is stretched horizontally.

  15. #14

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    143
    Quote Originally Posted by kearton View Post
    I wish someone (else, my comments go in one ear and out the other) would tell that to one of the IT staff here. He hasn't updated his video driver. I know I'm a pedant, but I just can't stand seeing things displayed in 4:3 on a widescreen monitor. The entire thing is stretched horizontally.
    One thing that annoys me as well that it, TFT screens being set to anything except their native resolution always looks rubbish.

SHARE:
+ Post New Thread

Similar Threads

  1. Forcing a screen resolution?
    By tmcd35 in forum How do you do....it?
    Replies: 0
    Last Post: 4th March 2009, 12:38 PM
  2. Screen resolution
    By rh91uk in forum Windows Vista
    Replies: 1
    Last Post: 12th November 2008, 06:20 PM
  3. All user screen resolution
    By theeldergeek in forum Windows
    Replies: 7
    Last Post: 14th May 2008, 12:39 PM
  4. Screen Resolution
    By plock in forum Windows
    Replies: 6
    Last Post: 17th December 2007, 02:56 PM
  5. Detect Ctitrix session from within bat/vbs?
    By Geoff in forum Thin Client and Virtual Machines
    Replies: 9
    Last Post: 19th July 2006, 11:24 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •