+ Post New Thread
Page 1 of 5 12345 LastLast
Results 1 to 15 of 65
Scripts Thread, Copy image file based on screen resolution. in Coding and Web Development; Hi, I would like a script that will copy a image file based on the screen resolution. What i am ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453

    Copy image file based on screen resolution.

    Hi,

    I would like a script that will copy a image file based on the screen resolution. What i am trying to do it set it as the W7 logon wallpaper. The issue is the wallpaper will looked stretched on different screens around if i use a single file. So i am adapting this script - Desktop background issue

    I have tweaked it and my code looks like this. Can anyone see any errors please?

    Thanks

    Code:
    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2") 
    Set objSh = CreateObject("Wscript.Shell")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) 
    For Each objItem in colItems 
        intHorizontal = objItem.ScreenWidth 
        intVertical = objItem.ScreenHeight 
    Next
    
    strResolution = CStr(intHorizontal) & " x " & CStr(intVertical)
    
    Select Case strResolution
    Case "1024 x 768"
            strWallpaperPath = "\\bishopsgarth\dfs$\Public$\WALLPAPERS\1024x768.bmp"
    Case "1280 x 1024"
            strWallpaperPath = "\\bishopsgarth\dfs$\Public$\WALLPAPERS\1280x1024.bmp"
    Case "1440 x 900"
            strWallpaperPath = "\\bishopsgarth\dfs$\Public$\WALLPAPERS\1440x900.bmp"
    Case "1920 x 1080"
            strWallpaperPath = "\\bishopsgarth\dfs$\Public$\WALLPAPERS\1920x1080.bmp"
    Case Else
    End Select
    
    
    filesys.CopyFile strWallpaperPath, "c:\Windows\System32\Oobe\info\backgrounds"

  2. #2

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    Can i bump this please

    Although i dont need it for the above purpose anymore i now need it for something else.

    Thanks

  3. #3

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by FN-GM View Post
    Can i bump this please

    Although i dont need it for the above purpose anymore i now need it for something else.

    Thanks
    What error is it giving etc?

    Steve

  4. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    Using the below code I get the attached message. I am running it from an elevated command prompt. Thanks

    Code:
    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    Set objSh = CreateObject("Wscript.Shell")
    
    ScreenRes = funcScreenResolution() 
    Function funcScreenResolution() 
        Set objIE = CreateObject("InternetExplorer.Application") 
        objIE.Navigate("about:blank") 
        Do Until objIE.readyState = 4: Loop 
            width = objIE.document.ParentWindow.screen.width 
            height = objIE.document.ParentWindow.screen.height 
        objIE.Quit 
        funcScreenResolution = array(width,height) 
    End Function 
     
    strResolution = ScreenRes(0) & " x " & ScreenRes(1)
    
    Select Case strResolution
    Case "800 x 600"
            strWallpaperPath = "C:\Temp\Source\800x600.jpg"
    Case "1024 x 768"
            strWallpaperPath = "C:\Temp\Source\1024x768.jpg"
    Case "1152 x 864"
            strWallpaperPath = "C:\Temp\Source\1152x864.jpg"
    Case "1280 x 768"
            strWallpaperPath = "C:\Temp\Source\1280x768.jpg"
    Case "1280 x 800"
            strWallpaperPath = "C:\Temp\Source\1280x800.jpg"
    Case "1280 x 1024"
            strWallpaperPath = "C:\Temp\Source\1280x1024.jpg"
    Case "1366 x 768"
            strWallpaperPath = "C:\Temp\Source\1366x768.jpg"
    Case "1440 x 900"
            strWallpaperPath = "C:\Temp\Source\1440x900.jpg"
    Case "1680 x 1050"
            strWallpaperPath = "C:\Temp\Source\1680x1050.jpg"
    Case "1920 x 1080"
            strWallpaperPath = "C:\Temp\Source\1920x1080.jpg"
    Case "1920 x 1440"
            strWallpaperPath = "C:\Temp\Source\1920x1440.jpg"
    Case Else
    End Select
    
    
    filesys.CopyFile strWallpaperPath, "C:\Temp\Dest"
    Attached Images Attached Images

  5. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    That's what it says Permissions. Not the script as such.

    Working here fine (But you'll want to change the last line as you're copy a file into a file without a filetype on, not the folder Dest.

    Edit - to rephrase you'll want an \ on end of Dest, or make it a proper filename, and try that with permission wise.

    Steve
    Last edited by Steve21; 19th February 2013 at 10:37 AM.

  6. Thanks to Steve21 from:

    FN-GM (19th February 2013)

  7. #6

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    Edit - to rephrase you'll want an \ on end of Dest, or make it a proper filename, and try that with permission wise.
    That did the trick, thanks

    Do you think it will work as a startup script please?

  8. #7

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by FN-GM View Post
    That did the trick, thanks

    Do you think it will work as a startup script please?
    Not sure this version will, as you're running IE and getting data without being logged on.

    Could try it I guess. Sorry, not much help

    Steve

  9. #8

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    I just tried it, it copies the 1024X768 image, this isnt correct. Any ideas how I could get this to work please?

  10. #9

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by FN-GM View Post
    I just tried it, it copies the 1024X768 image, this isnt correct. Any ideas how I could get this to work please?
    The second script isn't getting your screen height/width though, it's getting IE windows. The first one is getting screen size.

    What is it you're actually after?

    Steve

  11. #10

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    Quote Originally Posted by Steve21 View Post
    The second script isn't getting your screen height/width though, it's getting IE windows. The first one is getting screen size.

    What is it you're actually after?

    Steve
    The first one doesn't work at all on Windows 8 but works fine on Windows 7.

    Its for the Windows 8 lock screen image. You have to point to a specific image, i want it to display the one at the correct resolution and not just stretch a generic one.

    This script give me the attached error.

    Code:
    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2") 
    Set objSh = CreateObject("Wscript.Shell")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) 
    For Each objItem in colItems 
        intHorizontal = objItem.ScreenWidth 
        intVertical = objItem.ScreenHeight 
    Next
    
    strResolution = CStr(intHorizontal) & " x " & CStr(intVertical)
    
    Select Case strResolution
    Case "800 x 600"
            strWallpaperPath = "C:\Temp\Source\800x600.jpg"
    Case "1024 x 768"
            strWallpaperPath = "C:\Temp\Source\1024x768.jpg"
    Case "1152 x 864"
            strWallpaperPath = "C:\Temp\Source\1152x864.jpg"
    Case "1280 x 768"
            strWallpaperPath = "C:\Temp\Source\1280x768.jpg"
    Case "1280 x 800"
            strWallpaperPath = "C:\Temp\Source\1280x800.jpg"
    Case "1280 x 1024"
            strWallpaperPath = "C:\Temp\Source\1280x1024.jpg"
    Case "1366 x 768"
            strWallpaperPath = "C:\Temp\Source\1366x768.jpg"
    Case "1440 x 900"
            strWallpaperPath = "C:\Temp\Source\1440x900.jpg"
    Case "1680 x 1050"
            strWallpaperPath = "C:\Temp\Source\1680x1050.jpg"
    Case "1920 x 1080"
            strWallpaperPath = "C:\Temp\Source\1920x1080.jpg"
    Case "1920 x 1440"
            strWallpaperPath = "C:\Temp\Source\1920x1440.jpg"
    Case Else
    End Select
    
    filesys.CopyFile strWallpaperPath, "C:\Temp\Dest\Lock-Screen-Image.jpg"
    Attached Images Attached Images
    Last edited by FN-GM; 19th February 2013 at 11:59 AM.

  12. #11
    Jamo's Avatar
    Join Date
    Jan 2009
    Posts
    1,354
    Thank Post
    66
    Thanked 175 Times in 147 Posts
    Rep Power
    60
    If you are changing your logon background you could go the oobe route?

    Customize the Windows 7 Login/Logon Background | InterWorks, Inc.

  13. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by FN-GM View Post
    The first one doesn't work at all on Windows 8 but works fine on Windows 7.

    Its for the Windows 8 lock screen image. You have to point to a specific image, i want it to display the one at the correct resolution and not just stretch a generic one.

    This script give me the attached error.

    Code:
    dim filesys
    set filesys=CreateObject("Scripting.FileSystemObject")
    
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2") 
    Set objSh = CreateObject("Wscript.Shell")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) 
    For Each objItem in colItems 
        intHorizontal = objItem.ScreenWidth 
        intVertical = objItem.ScreenHeight 
    Next
    
    strResolution = CStr(intHorizontal) & " x " & CStr(intVertical)
    
    Select Case strResolution
    Case "800 x 600"
            strWallpaperPath = "C:\Temp\Source\800x600.jpg"
    Case "1024 x 768"
            strWallpaperPath = "C:\Temp\Source\1024x768.jpg"
    Case "1152 x 864"
            strWallpaperPath = "C:\Temp\Source\1152x864.jpg"
    Case "1280 x 768"
            strWallpaperPath = "C:\Temp\Source\1280x768.jpg"
    Case "1280 x 800"
            strWallpaperPath = "C:\Temp\Source\1280x800.jpg"
    Case "1280 x 1024"
            strWallpaperPath = "C:\Temp\Source\1280x1024.jpg"
    Case "1366 x 768"
            strWallpaperPath = "C:\Temp\Source\1366x768.jpg"
    Case "1440 x 900"
            strWallpaperPath = "C:\Temp\Source\1440x900.jpg"
    Case "1680 x 1050"
            strWallpaperPath = "C:\Temp\Source\1680x1050.jpg"
    Case "1920 x 1080"
            strWallpaperPath = "C:\Temp\Source\1920x1080.jpg"
    Case "1920 x 1440"
            strWallpaperPath = "C:\Temp\Source\1920x1440.jpg"
    Case Else
    End Select
    
    filesys.CopyFile strWallpaperPath, "C:\Temp\Dest\Lock-Screen-Image.jpg"
    I'm guessing it's just returning null as that device ID doesn't exist in Win8. Can't you just remove the deviceID part and try it?

    ("Select * From Win32_DesktopMonitor") etc

    Steve

  14. Thanks to Steve21 from:

    FN-GM (1st August 2013)

  15. #13

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    @Jamo that only applies to windows 7 this is for Windows 8

    Steve will give it shot shortly

  16. #14


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,037
    Thank Post
    231
    Thanked 2,700 Times in 1,994 Posts
    Rep Power
    792
    Here's a way to do it in PowerShell.

    Code:
    function Get-ScreenResolution {
        [void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
        [void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
        $Screens = [system.windows.forms.screen]::AllScreens
    
        ForEach ($Screen in $Screens) {
      	$DeviceName = $Screen.DeviceName
    	$Width      = $Screen.Bounds.Width
    	$Height     = $Screen.Bounds.Height
    	$IsPrimary  = $Screen.Primary
    
        $OutputObj = New-Object -TypeName PSobject
        $OutputObj | Add-Member -MemberType NoteProperty -Name DeviceName -Value $DeviceName
        $OutputObj | Add-Member -MemberType NoteProperty -Name Width -Value $Width
        $OutputObj | Add-Member -MemberType NoteProperty -Name Height -Value $Height
        $OutputObj | Add-Member -MemberType NoteProperty -Name IsPrimaryMonitor -Value $IsPrimary
        $OutputObj
    
        }
    }
    
    $Res = Get-ScreenResolution | Where IsPrimaryMonitor -eq True | Select Width,Height
    
    Switch($Res)
    {
        {($_.Width -eq  "800" -and $_.Height -eq  "600" )} { $wp =   "800x600.jpg"; break; } # 4:3
        {($_.Width -eq "1024" -and $_.Height -eq  "768" )} { $wp =  "1024x768.jpg"; break; } # 4:3
        {($_.Width -eq "1152" -and $_.Height -eq  "864" )} { $wp =  "1152x864.jpg"; break; } # 4:3
        {($_.Width -eq "1280" -and $_.Height -eq  "960" )} { $wp =  "1280x960.jpg"; break; } # 4:3
        {($_.Width -eq "1400" -and $_.Height -eq "1050" )} { $wp =  "1280x960.jpg"; break; } # 4:3
        {($_.Width -eq "1920" -and $_.Height -eq "1440" )} { $wp = "1920x1440.jpg"; break; } # 4:3
        {($_.Width -eq "1600" -and $_.Height -eq "1200" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1280" -and $_.Height -eq  "768" )} { $wp =  "1280x768.jpg"; break; } # 5:3
        {($_.Width -eq "1280" -and $_.Height -eq "1024" )} { $wp = "1280x1024.jpg"; break; } # 5:4
        {($_.Width -eq "1280" -and $_.Height -eq  "720" )} { $wp =  "1280x720.jpg"; break; } # 16:9
        {($_.Width -eq "1366" -and $_.Height -eq  "768" )} { $wp =  "1366x768.jpg"; break; } # 16:9
        {($_.Width -eq "1920" -and $_.Height -eq "1080" )} { $wp = "1920x1080.jpg"; break; } # 16:9
        {($_.Width -eq "2560" -and $_.Height -eq "1440" )} { $wp = "2560x1440.jpg"; break; } # 16:9
        {($_.Width -eq "1280" -and $_.Height -eq  "800" )} { $wp =  "1280x800.jpg"; break; } # 16:10
        {($_.Width -eq "1440" -and $_.Height -eq  "900" )} { $wp =  "1440x900.jpg"; break; } # 16:10
        {($_.Width -eq "1680" -and $_.Height -eq "1050" )} { $wp = "1680x1050.jpg"; break; } # 16:10
        {($_.Width -eq "1920" -and $_.Height -eq "1200" )} { $wp = "1920x1200.jpg"; break; } # 16:10
        {($_.Width -eq "2560" -and $_.Height -eq "1600" )} { $wp = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1024" -and $_.Height -eq  "600" )} { $wp =  "1024x600.jpg"; break; } # 17:10
        {($_.Width -eq "2560" -and $_.Height -eq "1080" )} { $wp = "2560x1080.jpg"; break; } # 21:9
        default { $wp = $null }
    }
    
    if ( $wp -ne $null ) { 
      Copy-Item -Path "${env:SystemDrive}\Temp\$wp" -Destination "${env:SystemDrive}\Temp\Lock-Screen-Image.jpg" -Force -ErrorAction SilentlyContinue
    }
    If you used the highest resolution for a particular aspect ratio, you would only need seven unique wallpapers in the script above despite there being 20 resolutions. i.e. 1600x1200 would be scaled down to 1024x768, 800x600 etc.
    Last edited by Arthur; 20th February 2013 at 12:05 AM. Reason: Added Aspect Ratios

  17. Thanks to Arthur from:

    FN-GM (1st August 2013)

  18. #15

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,049
    Thank Post
    888
    Thanked 1,728 Times in 1,491 Posts
    Blog Entries
    12
    Rep Power
    453
    Hi @Arthur i have just got back to working at this (BSF stuff took over). So are you saying if we didn't have an exact resolution the script would copy the best match? thanks

SHARE:
+ Post New Thread
Page 1 of 5 12345 LastLast

Similar Threads

  1. File blocking based on a hash value
    By phodge in forum Windows
    Replies: 1
    Last Post: 30th March 2010, 03:11 PM
  2. VBS - wshell.run based on file contents?
    By ahuxham in forum Scripts
    Replies: 14
    Last Post: 17th November 2009, 03:10 PM
  3. [CLOSED] Layout Issue: Main webpage not resizing based on screen resolution
    By Pottsey in forum EduGeek.net Site Problems
    Replies: 6
    Last Post: 27th February 2008, 02:10 PM
  4. Copy 2 files to every computer on the network
    By dezt in forum How do you do....it?
    Replies: 7
    Last Post: 5th July 2006, 11:43 AM
  5. Replies: 6
    Last Post: 20th October 2005, 06:48 PM

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
  •