A PowerShell script to update the Windows 7 and Windows 10 lock screen image.

By | October 12, 2018

This was the mission at work, and the hardest part is that I don’t know PowerShell, but I had two things going for me.

1, Windows 7 keeps the lock screen image in C:\Windows\System32\oobe\info\backgrounds (C:\Windows\sysnative\oobe\info\backgrounds for x32). As long as it’s called “backgroundDefault.jpg” and is 256kb or smaller, Win7 is happy.

2, The policy for Win10 had already been set to use C:\Utils\backgroundDefault.jpg for the background image.

Policy settings




The Windows 7 part is easy. Replace the file.

Windows 10 is trickier because it will read the file and then “cache” it to a different directory (C:\ProgramData\Microsoft\Windows\SystemData) where it uses it.  This SystemData directory is inaccessible with your user rights, so you need to take ownership of the directory, then the files, recursively, then delete the whole SystemData directory.
Once THAT is done, Windows 10 will read the file specified in your policy and recreate the SystemData directory with it.

(Get-WmiObject -class Win32_OperatingSystem).Caption
$Ver = [System.Environment]::OSVersion.Version.Major
$w7img = "PSScriptRoot\Win7\backgroundDefault.jpg"
$w10img = "PSScriptRoot\Win10\backgroundDefault.jpg"
$32path = "C:\Windows\SysNative\oobe\info\backgrounds\"
$64path = "C:\Windows\System32\oobe\info\backgrounds\"
$W10path = "C:\Utils\"

If ($Ver -lt 10){
#Win 7
if(Test-Path HKLM:\SOFTWARE\WOW6432Node){
#64 bit
Copy-Item -Path $w7img -Destination $64Path -Force
#32 bit
Copy-Item -Path $w7img -Destination $32Path -Force
Start-Process -filePath "$env:systemRoot\system32\takedown.exe" -ArgumentList "/F "$env:programData\Microsoft\Windows\Systemdata" /R /D Y" -NoNewWindow -Wait
Start-Process -filePath "$env:systemRoot\system32\icacls" -ArgumentList " `"$env:programData\Microsoft\Windows\Systemdata" /reset /T /C" -NoNewWindow -Wait
Copy-Item -Path $w10img -Destination $w10Path -Force

Leave a Reply

Your email address will not be published.