+ Post New Thread
Page 3 of 5 FirstFirst 12345 LastLast
Results 31 to 45 of 65
Scripts Thread, Copy image file based on screen resolution. in Coding and Web Development; What ver of powershell are you running? Ben...
  1. #31

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,610
    Thank Post
    730
    Thanked 1,688 Times in 1,502 Posts
    Rep Power
    433
    What ver of powershell are you running?

    Ben

  2. #32

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    Version 4

  3. #33


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,421
    Thank Post
    243
    Thanked 2,827 Times in 2,086 Posts
    Rep Power
    815
    Quote Originally Posted by FN-GM View Post
    This might be it. I opened powershell and typed Get-ScreenResolution and it returns this
    That would be because you haven't called the function. e.g. by dot sourcing. If you run the script as shown in post #22 you wouldn't need to do this however.

    What happens when you copy-and-paste the script into the script pane in the PowerShell ISE and then run it?
    Last edited by Arthur; 2nd November 2013 at 12:29 PM.

  4. Thanks to Arthur from:

    FN-GM (2nd November 2013)

  5. #34

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    I am running the script in post 22. Just run that in the powershell to see what would happen.

    I copied and pasted it into ISE and press run at the bottom on the status bar it returns completed.

    In C:\temp the folder is not there.

    When i use the command at the side its not showing Get-ScreenResolution is an option.
    Last edited by FN-GM; 2nd November 2013 at 12:37 PM.

  6. #35


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,421
    Thank Post
    243
    Thanked 2,827 Times in 2,086 Posts
    Rep Power
    815
    Quote Originally Posted by FN-GM View Post
    In C:\temp the folder is not there.
    Are the lock screen images all located in C:\Temp or in sub-folders?

    As you can see from the animated GIF below, when I run the script it works fine.



    Quote Originally Posted by FN-GM View Post
    When I use the command at the side it's not showing Get-ScreenResolution is an option.
    Do you mean in the Command window (pictured below)? Get-ScreenResolution won't show up there.

    Last edited by Arthur; 2nd November 2013 at 01:12 PM.

  7. Thanks to Arthur from:

    FN-GM (2nd November 2013)

  8. #36

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    They are in C:\Temp. Well why doesn't it work?

  9. #37


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,421
    Thank Post
    243
    Thanked 2,827 Times in 2,086 Posts
    Rep Power
    815
    Quote Originally Posted by FN-GM View Post
    Screen res is 1366x768.
    Ah ha! I think I have figured it out.

    My script is looking for an image file named 2560x1440.jpg in C:\Temp for the resolution 1366x768. If you have an image called 1366x768.jpg, that's why it isn't working.

    Code:
    {($_.Width -eq "1366" -and $_.Height -eq  "768" )} { $wp = "2560x1440.jpg"; break; } # 16:9
    Because 2560x1440 and 1366x768 both have an aspect ratio of 16:9, if you save a wallpaper image with the former resolution into C:\Temp it will be scaled down to 1366x768 by Windows. This saves you from creating multiple images for monitors with the same aspect ratio.
    Last edited by Arthur; 2nd November 2013 at 05:24 PM.

  10. Thanks to Arthur from:

    FN-GM (2nd November 2013)

  11. #38

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    Yer i figured that out. my file name is 2560x1440.jpg (and is that size) thought we got it then

    EDIT 1: Ah hang on i get you 1 second....

    EDIT 2: I was right the first time, i do have 2560x1440.jpg

    Are we using the script from post 22?
    Last edited by FN-GM; 2nd November 2013 at 05:55 PM.

  12. #39

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    Hi @Arthur just had a test with your first script you posted on post 14 and that works. What are your thoguths?

  13. #40


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,421
    Thank Post
    243
    Thanked 2,827 Times in 2,086 Posts
    Rep Power
    815
    Quote Originally Posted by FN-GM View Post
    What are your thoughts?
    Does the script in post #16 work for you too? If it's just the script in post #22 I would use one of the others. They all do the same thing.

  14. Thanks to Arthur from:

    FN-GM (2nd November 2013)

  15. #41

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    Yer that works as well. Oddly didn't work the other day, but i put a new image since.

    Would it be more efficient for the script to detect the aspect ratio and copy the file? Instead of listing all the resolutions? Probably not worth messing with it now!!

    Also i dare take the mick and ask how to tweak it to set the wallpaper for our users? The VBS script we use doesn't always work 100% of the time I am pretty sure its because it uses IE to find the screen size. This is so it works on RDS servers.
    Last edited by FN-GM; 2nd November 2013 at 06:24 PM.

  16. #42

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    Urgh, its doing the folder thing again. I give up today!

  17. #43


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,421
    Thank Post
    243
    Thanked 2,827 Times in 2,086 Posts
    Rep Power
    815
    Quote Originally Posted by FN-GM View Post
    Urgh, it's doing the folder thing again.
    I have found a different way to detect the resolution and select the image based on the aspect ratio. Hopefully it will work this time (although you may want to leave it until the morning).

    Code:
    Add-Type -AssemblyName System.Windows.Forms
    $Width  = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
    $Height = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
    $Ratio  = $Width/$Height
    
    Switch($Ratio)
    {
      "1.25"             { $Res = "1280x1024"; break; } # 5:4
      "1.33333333333333" { $Res = "1600x1200"; break; } # 4:3
      "1.6"              { $Res = "2560x1600"; break; } # 16:10
      "1.66666666666667" { $Res = "1280x768";  break; } # 5:3
      "1.77777777777778" { $Res = "2560x1440"; break; } # 16:9
      "1.77864583333333" { $Res = "1366x768";  break; } # 683:384
      "2.37037037037037" { $Res = "2560x1080"; break; } # 64:27
      default            { $Res = $null }
    }
    
    # Append extension to resolution
    $Source = "{0}.jpg" -f $Res
    
    # Copy lockscreen image
    if ( $Res -ne $null ) {
      Copy-Item -Path "${env:SystemDrive}\Temp\$Source" -Destination "${env:SystemDrive}\Temp\Lock-Screen-Image.jpg" -Force -Verbose
    }
    
    
    
    
    
    # ------------------------------------------------------------------------
    # SARs & Common Resolutions (http://goo.gl/XJ5U)
    # ------------------------------------------------------------------------
    # 4:3       800x600, 1024x768, 1600x1200
    # 5:3       800x480, 1280x768
    # 5:4       1280x1024
    # 16:9      1280x720, 1600x900, 1920x1080, 2560x1440
    # 16:10     1280x800, 1440x900, 1680x1050, 1920x1200, 2560x1600, 2880◊1800
    # 64:27     2560x1080
    # 128:75    1024x600
    # 683:384   1366x768
    # ------------------------------------------------------------------------
    Last edited by Arthur; 3rd November 2013 at 12:58 AM. Reason: Made some corrections

  18. #44

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,610
    Thank Post
    730
    Thanked 1,688 Times in 1,502 Posts
    Rep Power
    433
    I wouldn't use silentlycontinue as the error action though.

    Ben

  19. #45

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    16,235
    Thank Post
    894
    Thanked 1,780 Times in 1,534 Posts
    Blog Entries
    12
    Rep Power
    462
    @Arthur that works a treat. Works perfectly!!! (not tried as a startup script yet)

    Obviously these wallpapers are scaled down, How do i figure out what max resolution to go upto please? Also If i need to add new resolutions how do i figure out these codes please?

SHARE:
+ Post New Thread
Page 3 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, 04:11 PM
  2. VBS - wshell.run based on file contents?
    By ahuxham in forum Scripts
    Replies: 14
    Last Post: 17th November 2009, 04: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, 03: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, 12:43 PM
  5. Replies: 6
    Last Post: 20th October 2005, 07: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
  •