Skip to content

Instantly share code, notes, and snippets.

@ctsstc
Last active April 20, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctsstc/6a6b57bb55ad37839ff2dc36aa208d95 to your computer and use it in GitHub Desktop.
Save ctsstc/6a6b57bb55ad37839ff2dc36aa208d95 to your computer and use it in GitHub Desktop.
Save Windows Login Backgrounds on Login / Workstation Unlock

Automatically Save Windows Login Backgrounds on Login

This will add a sheduled task to run the powershell script on login/workstation unlock without displaying a window.

Note: you can also try importing the XML file below for the task ๐Ÿคž

General Tab

  1. Open Task Scheduler
  2. Create Task under Task Scheduler Library
  3. Under Security Options:
    • Run whether user is logged on or not
      • This allows the window to be hidden
    • Do not store password.
    • Run with highest privileges
  4. I had Configure for: Windows 10 although I'm not sure if it matters

Triggers Tab

  1. Add a New... trigger
  2. Begin the task: On workstation unlock
    • You can likely add more but I did not test them
  3. Specific user: Change User...; select your user if you just want it for your account

Actions Tab

  1. Add a New... action
  2. Action: Start a program
  3. Program/script: powershell
  4. Add arguments: -ExecutionPolicy Bypass -File "C:\Users\coder\Pictures\windows login backgrounds\_pull.ps1"
    • Change out the path to match wherever you saved the _pull.ps1 script

SUCCESS! ๐ŸŽ‰๐Ÿš€

Profit! Now every time you log in the background will be saved in a backgrounds directory next to the script.

# Set the working path to the script's path
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Push-Location $dir
# Create backgrounds directory if it does not exist
if (!(Test-Path .\backgrounds)) { New-Item -ItemType Directory -Path .\backgrounds }
# Get the path to the Windows login backgrounds for the current user
$WindowsImagesPath = "$env:USERPROFILE\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
# Copy images from the path to the backgrounds directory here
cp -r $windowsImagesPath\* .\backgrounds
# Add jpg extension to all files in the backgrounds directory without a jpg extension using Move-Item -Force
Get-ChildItem -Path .\backgrounds -Exclude *.jpg -Recurse | ForEach-Object { Move-Item -Path $_.FullName -Destination "$($_.FullName).jpg" -Force }
# Rename-Item doesn't seem to support overwriting; don't let it's -Force flag fool you either -- that's not what it does
# Get-ChildItem -Path .\backgrounds -Exclude *.jpg -Recurse | Rename-Item -NewName { $_.Name + ".jpg" } -Force
# Useful to debug the window before it goes away if there's any errors
# Write-Host "Press any key to continue..."
# $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2023-02-09T01:11:38.3033556</Date>
<Author>i9Beast\coder</Author>
<Description>Saves the MS Login Backgrounds</Description>
<URI>\CTS_AE\Save MS Login Backgrounds</URI>
</RegistrationInfo>
<Triggers>
<SessionStateChangeTrigger>
<Enabled>true</Enabled>
<StateChange>SessionUnlock</StateChange>
<UserId>i9Beast\coder</UserId>
</SessionStateChangeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-373059960-1286789452-1330396964-1002</UserId>
<LogonType>S4U</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-ExecutionPolicy Bypass -File "C:\Users\coder\Pictures\windows login backgrounds\_pull.ps1"</Arguments>
</Exec>
</Actions>
</Task>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment