Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PowerShell script to copy the images Windows 10 uses for its lockscreen to
- # the users Pictures folder in two subdirectories:
- # *'Wallpapers widescreen' (for images that are wider than they are tall) and
- # *'Wallpapers longscreen' (for images that are taller than they are wide).
- # The subdirectories will be created if they do not exist.
- #
- # Run this script (as admin) with '-task' to create a scheduled task that will
- # automatically run this script when you log in. The script will register
- # itself at its current location, with its current filename. Put the script in
- # a place where you want to keep it before creating the task!
- param(
- [switch]$task = $false
- )
- # Create the scheduled task
- if($task){
- $description = "Copies the images that Windows uses on the lockscreen to Pictures so that they can be used as wallpapers"
- $action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument ('-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File "'+$PSCommandPath+'"')
- $trigger = New-ScheduledTaskTrigger -AtLogOn -User ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
- Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "Copy Lockscreen Images" -Description $description
- }
- add-type -AssemblyName System.Drawing
- # This is the secret path where Windows 10 keeps its lockscreen images. If you
- # open this folder yourself, you'll see a bunch of files with long hexadecimal
- # numbers as names and no extensions. If you rename the files to
- # 'something.jpg' you'll find that some, but not all, are actually images. The
- # folder includes all sorts of images used by Windows, including the icons for
- # Candy Crush and other 'promotional' games. But it also includes our precious
- # lockscreen images in both landscape and portrait orientations.
- $source_path = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\"
- # We'll store the images in you 'Pictures' folder.
- $base_path = [environment]::GetFolderPath('MyPictures')
- # This is the path for landscape images.
- $wide_path = Join-Path -Path $base_path -ChildPath "Wallpapers widescreen\"
- if(!(Test-Path $wide_path)){
- New-Item -ItemType Directory -Force -Path $wide_path
- }
- # This is the path for portrait images.
- $long_path = Join-Path -Path $base_path -ChildPath "Wallpapers longscreen\"
- if(!(Test-Path $long_path)){
- New-Item -ItemType Directory -Force -Path $long_path
- }
- # Let's get a list of all files in our source path.
- $filelist = Get-ChildItem $source_path
- foreach($file in $filelist){
- # Try to load the file as an image.
- try{
- $img = [System.Drawing.Image]::FromFile($file.FullName);
- }
- # If this fails, it wasn't an image and we can skip to the next file.
- catch{
- continue;
- }
- # If the image is smaller than 1 Megapixel it's too small for a wallpaper.
- if($img.width * $img.height -lt 1000000){
- continue;
- }
- # Add ".jpg" to the name of the file and copy it the the right directory.
- # While a long hexadecimal number might not be the catchiest of names, at
- # least it's unique and helps us avoid multiple copies of the same image.
- $target_path = $file.name + ".jpg"
- if($img.width -gt $img.height){
- $target_path = Join-Path -Path $wide_path -ChildPath $target_path
- } else {
- $target_path = Join-Path -Path $long_path -ChildPath $target_path
- }
- Copy-Item $file.FullName $target_path
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement