+ Post New Thread
Page 4 of 5 FirstFirst 12345 LastLast
Results 46 to 60 of 65
Scripts Thread, Copy image file based on screen resolution. in Coding and Web Development; ...
  1. #46


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    Quote Originally Posted by FN-GM View Post
    That works a treat. Works perfectly!!!
    Fantastic!

    I also ran the script under the SYSTEM account and that worked too, so you shouldn't have any problems with it being a startup script.

    One further improvement that could be made would be to avoid copying the image every time the PC boots up (unless users frequently change their primary display?).



    Quote Originally Posted by FN-GM View Post
    how do I figure out what max resolution to go up to please?
    I don't think there is a limit for how large the lock screen images can be (unlike with the logon screen background in Windows 7).

    Re: resolutions. Do you already know the native monitor resolutions for all of your Windows 8/8.1 PCs? If so, simply choose the highest one for a given aspect ratio. The maximum image resolution depends entirely on which monitors you have. After all, there isn't any point in creating a lock screen image that's larger than 1920x1200 if the largest 16:10 monitor you have is a 24" LCD, since it will only use up more disk space and take longer to process.

    For example, say you have a 14" laptop (1280x800) and a desktop PC with 30" LCD (2560x1600). Both have aspect ratios of 16:10 which means you can use the same image on both computers. Rather than scale the 1280x800 image up and potentially become fuzzy/pixelated on the 30" LCD, it would be better to have the 2560x1600 image automatically scaled down by Windows. In this case, the max. resolution is 2560x1600.

    Quote Originally Posted by FN-GM View Post
    Also if I need to add new resolutions how do I figure out these codes please?
    Most of the common aspect ratios are already listed in the script, so you shouldn't need to change it that often.

    The first set of numbers (highlighted in blue below) are calculated by either dividing the horizontal resolution by the vertical resolution or the first number in the ratio, by the second (highlighted in purple). I think these are called the antecedent and consequent? PowerShell uses these numbers to work out which image file to select.

    The resolutions (highlighted in red) are the highest resolutions you want to support for each aspect ratio. These eventually become the filenames for your lock screen images.

    Let's say you buy some brand new (3840x2160) Dell UP3214Q or Asus PQ321Q monitors. Because the aspect ratio is 16:9 you would simply change 2560x1440 to 3840x2160 on the line that starts with 1.77777777777778 and create a new lock screen image: 3840x2160.jpg. This image would work for every resolution with a 16:9 aspect ratio: 3840x2160 2560x1440 1920x1080 1600x900 1280x720 etc.

    The line highlighted in orange shows how you would add a new resolution and aspect ratio. In this example you would divide 2560 by 1700 to get 1.50588235294118.

    Btw, did you spot the table at the bottom of the script? The goo.gl URL will take you to a useful article on Wikipedia.

    Code:
    Switch($Ratio)
    {
      "1.25"             { $Res = "1280x1024"; break; } # 5:4
      "1.33333333333333" { $Res = "1600x1200"; break; } # 4:3
      "1.50588235294118" { $Res = "2560x1700"; break; } # 128:85
      "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 }
    }
    Note. The resolution 2560x1080 is commonly used on LCDs that are advertised as having an aspect ratio of 21:9 (such as the 29" Dell U2913WM). However, this is not actually the correct aspect ratio - it is 64:27 (2.37037037037037). There's a handy calculator on this website if you want to double-check aspect ratios.

  2. Thanks to Arthur from:

    FN-GM (3rd November 2013)

  3. #47

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Thanks for the post, just nipping out but had a quick scan. Will read more later.

    I do know what resolutions we have out there. Just if we get anything new i want to avoid having to change stuff. So will make them large and i can then scale them all down, hopefully should work for everything.

    Thanks for the help.

  4. #48


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    Quote Originally Posted by FN-GM View Post
    how to tweak it to set the wallpaper for our users? The VBS script we use doesn't always work 100% of the time
    You might be interested in the PowerShell script below that I found a couple of days ago.

    Code:
    function Set-Wallpaper
    {
        param(
            [Parameter(Mandatory=$true)]
            $Path,
            [ValidateSet('Center', 'Stretch')]
            $Style = 'Stretch'
        )
        
        Add-Type @"
        using System;
        using System.Runtime.InteropServices;
        using Microsoft.Win32;
    
        namespace Wallpaper
        {
            public enum Style : int
            {
                Center, Stretch
            }
            public class Setter {
                public const int SetDesktopWallpaper = 20;
                public const int UpdateIniFile = 0x01;
                public const int SendWinIniChange = 0x02;
                [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
                private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
                public static void SetWallpaper ( string path, Wallpaper.Style style ) {
                    SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
                    RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
    
                    switch(style)
                    {
                        case Style.Stretch :
                            key.SetValue(@"WallpaperStyle", "2"); 
                            key.SetValue(@"TileWallpaper", "0");
                            break;
                        case Style.Center :
                            key.SetValue(@"WallpaperStyle", "1"); 
                            key.SetValue(@"TileWallpaper", "0"); 
                            break;
                    }
                    key.Close();
                }
            }
        }
    "@
        
        [Wallpaper.Setter]::SetWallpaper($Path, $Style)
    }
    
    Set-Wallpaper -Path 'C:\Windows\Web\Wallpaper\Windows\img0.jpg'
    All you need to do is change the path to the image (highlighted in red) and then run it as a logon script.
    Last edited by Arthur; 12th January 2014 at 06:00 PM.

  5. Thanks to Arthur from:

    FN-GM (12th January 2014)

  6. #49

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Thanks, I am going to be getting on with the Windows 8 stuff again now we have moved into the new build.

  7. #50

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Hi @Arthur I am using the below script. Got an issue though. The screen resolution is 1366x768 but if you use the script and a startup script it is using the 1600x1200 wallpaper. If I run it when I am logged into Windows it works fine. Do you have any thoughts on that please?

    Thnaks

    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}\Program Files\FPHS-Software\FPHS-Wallpaper\Logon Screen\Source\$Source" -Destination "${env:SystemDrive}\Program Files\FPHS-Software\FPHS-Wallpaper\Logon Screen\Active Logon Screen\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, 28801800
    # 64:27     2560x1080
    # 128:75    1024x600
    # 683:384   1366x768
    # ------------------------------------------------------------------------

  8. #51


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    Quote Originally Posted by FN-GM View Post
    Do you have any thoughts on that please?
    Not yet, but I'll have a look later.

  9. #52

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Cheers. I will have some time to have a good look at it tomorrow. Its weird i must say.

  10. #53


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    Quote Originally Posted by FN-GM View Post
    The screen resolution is 1366x768 but if you use the script and a startup script it is using the 1600x1200 wallpaper. If I run it when I am logged into Windows it works fine.
    Could you run the following as a startup script and then post the contents of the text file?

    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
    
    $Width, $Height, $Ratio -join ',' | Out-File -FilePath C:\Temp\StartupRes.txt -Force

  11. #54

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    here we go

    1024,768,1.33333333333333


    Cheers

  12. #55


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    Quote Originally Posted by FN-GM View Post
    The screen resolution is 1366x768 but if you use the script and a startup script it is using the 1600x1200 wallpaper.
    Quote Originally Posted by FN-GM View Post
    here we go: 1024,768,1.33333333333333
    That's really strange! Does the affected PC have only one display attached? Is it a VGA monitor?

  13. #56

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Tried it on 2 machines. One with a VGA monitor and the other is a laptop.

    Cheers

  14. #57

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Trying to think of some work arounds. What do you think of a scheduled task that runs a few minutes after booting?

  15. #58


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    8,870
    Thank Post
    226
    Thanked 2,666 Times in 1,965 Posts
    Rep Power
    785
    On the PC that didn't work, is its monitor detected as a generic PnP monitor?

    Quote Originally Posted by FN-GM View Post
    What do you think of a scheduled task that runs a few minutes after booting?
    That sound like a much better idea.

  16. #59

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Quote Originally Posted by Arthur View Post
    On the PC that didn't work, is its monitor detected as a generic PnP monitor?


    That sound like a much better idea.
    Been out off office for various reasons, will check in the morning.

  17. #60

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,939
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    @Arthur they are coming up generic PnP monitors.

    Thanks

SHARE:
+ Post New Thread
Page 4 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
  •