FN-GM Posted November 2, 2013 Author Posted November 2, 2013 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.
Arthur Posted November 2, 2013 Posted November 2, 2013 What does the following line look like in your version of the script? Are you just changing the folder names highlighted in red? Get-ChildItem -Path ${env:SystemDrive}\[color="#FF0000"]Temp[/color]\* -Include $wp | Copy-Item -Destination "${env:SystemDrive}\[color="#FF0000"]Temp[/color]\Lock-Screen-Image.jpg" -Force -Verbose
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 This might be it. I opened powershell and typed Get-ScreenResolution and it returns this: 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.
plexer Posted November 2, 2013 Posted November 2, 2013 Get-DisplayResolution Looks like it's now Get-DisplayResolution Ben
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 Get-DisplayResolution is also not recognized
Arthur Posted November 2, 2013 Posted November 2, 2013 (edited) 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? Edited November 2, 2013 by Arthur 1
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 (edited) 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. Edited November 2, 2013 by FN-GM
Arthur Posted November 2, 2013 Posted November 2, 2013 (edited) 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. http://i.imgur.com/m3GVWTr.gif 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. http://i.imgur.com/y5RvTv0.png Edited November 2, 2013 by Arthur 1
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 They are in C:\Temp. Well why doesn't it work?
Arthur Posted November 2, 2013 Posted November 2, 2013 (edited) 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. {($_.Width -eq "1366" -and $_.Height -eq "768" )} { $wp = "[color="#FF0000"]2560x1440.jpg[/color]"; 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. Edited November 2, 2013 by Arthur 1
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 (edited) 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? Edited November 2, 2013 by FN-GM
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 Hi @Arthur just had a test with your first script you posted on post 14 and that works. What are your thoguths?
Arthur Posted November 2, 2013 Posted November 2, 2013 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. 1
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 (edited) 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. Edited November 2, 2013 by FN-GM
FN-GM Posted November 2, 2013 Author Posted November 2, 2013 Urgh, its doing the folder thing again. I give up today!
Arthur Posted November 2, 2013 Posted November 2, 2013 (edited) 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). 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 # ------------------------------------------------------------------------ Edited November 2, 2013 by Arthur Made some corrections
plexer Posted November 2, 2013 Posted November 2, 2013 I wouldn't use silentlycontinue as the error action though. Ben
FN-GM Posted November 3, 2013 Author Posted November 3, 2013 @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?
Arthur Posted November 3, 2013 Posted November 3, 2013 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?). http://i.imgur.com/aKlSUfd.png 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. 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. Switch($Ratio) { "[color="#0000CD"]1.25[/color]" { $Res = "[color="#FF0000"]1280x1024[/color]"; break; } # [color="#4B0082"]5:4[/color] "[color="#0000CD"]1.33333333333333[/color]" { $Res = "[color="#FF0000"]1600x1200[/color]"; break; } # [color="#4B0082"]4:3[/color] [color="#ff6600"][i]"1.50588235294118" { $Res = "2560x1700"; break; } # 128:85[/i][/color] "[color="#0000CD"]1.6[/color]" { $Res = "[color="#FF0000"]2560x1600[/color]"; break; } # [color="#4B0082"]16:10[/color] "[color="#0000CD"]1.66666666666667[/color]" { $Res = "[color="#FF0000"]1280x768[/color]"; break; } # [color="#4B0082"]5:3[/color] "[color="#0000CD"]1.77777777777778[/color]" { $Res = "[color="#FF0000"]2560x1440[/color]"; break; } # [color="#4B0082"]16:9[/color] "[color="#0000CD"]1.77864583333333[/color]" { $Res = "[color="#FF0000"]1366x768[/color]"; break; } # [color="#4B0082"]683:384[/color] "[color="#0000CD"]2.37037037037037[/color]" { $Res = "[color="#FF0000"]2560x1080[/color]"; break; } # [color="#4B0082"]64:27[/color] 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. 1
FN-GM Posted November 3, 2013 Author Posted November 3, 2013 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.
Arthur Posted January 12, 2014 Posted January 12, 2014 (edited) 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. 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 '[color="#FF0000"]C:\Windows\Web\Wallpaper\Windows\img0.jpg[/color]' All you need to do is change the path to the image (highlighted in red) and then run it as a logon script. Edited January 12, 2014 by Arthur 1
FN-GM Posted January 12, 2014 Author Posted January 12, 2014 Thanks, I am going to be getting on with the Windows 8 stuff again now we have moved into the new build.
FN-GM Posted March 5, 2014 Author Posted March 5, 2014 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 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, 2880×1800 # 64:27 2560x1080 # 128:75 1024x600 # 683:384 1366x768 # ------------------------------------------------------------------------
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now