+ Post New Thread
Page 2 of 5 FirstFirst 12345 LastLast
Results 16 to 30 of 65
Scripts Thread, Copy image file based on screen resolution. in Coding and Web Development; Originally Posted by FN-GM So are you saying if we didn't have an exact resolution the script would copy the ...
  1. #16


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,911
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    Quote Originally Posted by FN-GM View Post
    So are you saying if we didn't have an exact resolution the script would copy the best match?
    Sort of. What I was thinking you could do is simply use the largest image for each aspect ratio because Windows should scale it down. This means you would only have to make seven wallpapers in total (less if you didn't require the 17:10 and 21:9 aspect ratios). I have modified the script below so that's it's a bit clearer (and corrected the typo in the previous version above).

    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 = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1024" -and $_.Height -eq  "768" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1152" -and $_.Height -eq  "864" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1280" -and $_.Height -eq  "960" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1400" -and $_.Height -eq "1050" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1920" -and $_.Height -eq "1440" )} { $wp = "1600x1200.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 = "2560x1440.jpg"; break; } # 16:9
        {($_.Width -eq "1366" -and $_.Height -eq  "768" )} { $wp = "2560x1440.jpg"; break; } # 16:9
        {($_.Width -eq "1920" -and $_.Height -eq "1080" )} { $wp = "2560x1440.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 = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1440" -and $_.Height -eq  "900" )} { $wp = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1680" -and $_.Height -eq "1050" )} { $wp = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1920" -and $_.Height -eq "1200" )} { $wp = "2560x1600.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
    }
    For example, 1600x1200.jpg would work for all monitors with a 4:3 aspect ratio.

  2. #17

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Thanks, will give that a try. Cheers Z

  3. #18

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    If the screen resolution changes will the wallpaper automatically update?

    Thanks

  4. #19


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,911
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    Quote Originally Posted by FN-GM View Post
    If the screen resolution changes will the wallpaper automatically update?
    Like when someone connects a projector to their laptop? Not sure.

  5. #20

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Quote Originally Posted by Arthur View Post
    Like when someone connects a projector to their laptop? Not sure.
    Yer or if a monitor get changed etc.

    Thanks

  6. #21

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    @Arthur just looking at your script again. Just gave it a try. It doesn't copy a file, but it creates a folder called Lock-Screen-Image.jpg. Any thoughts please?

  7. #22


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,911
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    Quote Originally Posted by FN-GM View Post
    Any thoughts please?
    Is works for me. Which OS and PowerShell version are you using?

    Can you try the following script?

    Code:
    #Requires –Version 3
    $ErrorActionPreference = "SilentlyContinue"
    
    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
    
          $Output = [PSCustomObject] @{
            'DeviceName'       = $DeviceName;
            'Width'            = $Width;
            'Height'           = $Height;
            'IsPrimaryMonitor' = $IsPrimary;
          }
       }
    }
    
    $Res = Get-ScreenResolution | Where IsPrimaryMonitor -eq $true | Select Width,Height
    
    Switch($Res)
    {
        {($_.Width -eq  "800" -and $_.Height -eq  "600" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1024" -and $_.Height -eq  "768" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1152" -and $_.Height -eq  "864" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1280" -and $_.Height -eq  "960" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1400" -and $_.Height -eq "1050" )} { $wp = "1600x1200.jpg"; break; } # 4:3
        {($_.Width -eq "1920" -and $_.Height -eq "1440" )} { $wp = "1600x1200.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 = "2560x1440.jpg"; break; } # 16:9
        {($_.Width -eq "1366" -and $_.Height -eq  "768" )} { $wp = "2560x1440.jpg"; break; } # 16:9
        {($_.Width -eq "1920" -and $_.Height -eq "1080" )} { $wp = "2560x1440.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 = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1440" -and $_.Height -eq  "900" )} { $wp = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1680" -and $_.Height -eq "1050" )} { $wp = "2560x1600.jpg"; break; } # 16:10
        {($_.Width -eq "1920" -and $_.Height -eq "1200" )} { $wp = "2560x1600.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 ) { 
      Get-ChildItem -Path ${env:SystemDrive}\Temp\* -Include $wp | Copy-Item -Destination "${env:SystemDrive}\Temp\Lock-Screen-Image.jpg" -Force -Verbose
    }

  8. #23

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Using 8.1 not sure on Powershell version, what comes with 8.1?. Sorry its taken so long, i got tried up with BSF, then decided to wait until 8.1

    I will give that new script a try.

    Thanks again

  9. #24

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Just give it another go, the file doesn't copy, the destination folder is empty

  10. #25


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,911
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    What's the resolution of the monitor on your test PC? Are you running the script under your account or System? Are the lock screen images stored in a folder on the C:\ drive or the network?

    When I ran the script, it copied the image named 2560x1440.jpg (in C:\Temp) to Lock-Screen-Image.jpg in the same folder. My PC is also running Windows 8.1 with PS 4.0.

  11. #26

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Screen res is 1366x768. Running it under an account with admin rights. All files stored locally.

    Will have another look, maybe i have done something stupid.

  12. #27


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,911
    Thank Post
    226
    Thanked 2,676 Times in 1,973 Posts
    Rep Power
    787
    What does the following line look like in your version of the script? Are you just changing the folder names highlighted in red?

    Code:
    Get-ChildItem -Path ${env:SystemDrive}\Temp\* -Include $wp | Copy-Item -Destination "${env:SystemDrive}\Temp\Lock-Screen-Image.jpg" -Force -Verbose

  13. #28

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    This might be it. I opened powershell and typed Get-ScreenResolution and it returns this:

    Code:
    PS C:\Temp> Get-ScreenResolution
    Get-ScreenResolution : The term 'Get-ScreenResolution' is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At line:1 char:1
    + Get-ScreenResolution
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (Get-ScreenResolution:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    It isnt liking the Get-ScreenResolution cmdlet.

  14. #29

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,618
    Thank Post
    648
    Thanked 1,619 Times in 1,449 Posts
    Rep Power
    421
    Get-DisplayResolution

    Looks like it's now Get-DisplayResolution

    Ben

  15. #30

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,961
    Thank Post
    886
    Thanked 1,710 Times in 1,478 Posts
    Blog Entries
    12
    Rep Power
    449
    Get-DisplayResolution is also not recognized

SHARE:
+ Post New Thread
Page 2 of 5 FirstFirst 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
  •