Thanks, will give that a try. Cheers Z
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).
For example, 1600x1200.jpg would work for all monitors with a 4:3 aspect ratio.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 }
Thanks, will give that a try. Cheers Z
If the screen resolution changes will the wallpaper automatically update?
Thanks
@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?
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 }
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
Just give it another go, the file doesn't copy, the destination folder is empty
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.
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.
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
This might be it. I opened powershell and typed Get-ScreenResolution and it returns this:
It isnt liking the Get-ScreenResolution cmdlet.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
Get-DisplayResolution
Looks like it's now Get-DisplayResolution
Ben
Get-DisplayResolution is also not recognized
There are currently 1 users browsing this thread. (0 members and 1 guests)