Solved Set lockscreen wallpaper with command prompt


Sheikh

Software Developer
Power User
VIP
Local time
12:27 AM
Posts
732
Location
Tehran, IRAN.
OS
Windows 11 Pro 25H2
Hey guys.
I have an image in "C:\Windows\Web\Screen" (its name is "lockscreenwallpaper.jpg").
How can I set it as lockscreen background with cmd?
I want to let the user change it later in settings so changing registry key may cause some restrcitions in settings.

Thanks.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 25H2
    Computer type
    Laptop
    Manufacturer/Model
    Huawei MateBook D15
    CPU
    Ryzen 5 3500U
    Memory
    8GB
    Graphics Card(s)
    Vega 8
    Screen Resolution
    FHD
    Hard Drives
    256GB Samsung SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    ESET Smart Security Premium
  • Operating System
    Windows 10 Enterprise LTSC 21H2
    Computer type
    Laptop
    Manufacturer/Model
    MSI GS73 6RF Stealth Pro
    CPU
    intel core i7 6700HQ
    Memory
    16GB
    Graphics card(s)
    Nvidia Geforce GTX1060 (6GB)
    Screen Resolution
    FHD
    Hard Drives
    128GB SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    Windows Defender
Code:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageStatus /t REG_DWORD /d 1 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImagePath /t REG_SZ /d "\\path\\to\\image" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageUrl /t REG_SZ /d "\\path\\to\\image" /f

Users are allowed to change their lock screen background, unless you apply a reg key which specifically blocks it.
 

My Computer

System One

  • OS
    Windows 7
Code:
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageStatus /t REG_DWORD /d 1 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImagePath /t REG_SZ /d "\\path\\to\\image" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageUrl /t REG_SZ /d "\\path\\to\\image" /f

Users are allowed to change their lock screen background, unless you apply a reg key which specifically blocks it.
Thanks dear garlin.❤️

Thread marked as solved.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 25H2
    Computer type
    Laptop
    Manufacturer/Model
    Huawei MateBook D15
    CPU
    Ryzen 5 3500U
    Memory
    8GB
    Graphics Card(s)
    Vega 8
    Screen Resolution
    FHD
    Hard Drives
    256GB Samsung SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    ESET Smart Security Premium
  • Operating System
    Windows 10 Enterprise LTSC 21H2
    Computer type
    Laptop
    Manufacturer/Model
    MSI GS73 6RF Stealth Pro
    CPU
    intel core i7 6700HQ
    Memory
    16GB
    Graphics card(s)
    Nvidia Geforce GTX1060 (6GB)
    Screen Resolution
    FHD
    Hard Drives
    128GB SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    Windows Defender
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageStatus /t REG_DWORD /d 1 /f reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImagePath /t REG_SZ /d "\\path\\to\\image" /f reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" /v LockScreenImageUrl /t REG_SZ /d "\\path\\to\\image" /f
Users are allowed to change their lock screen background, unless you apply a reg key which specifically blocks it.
This isn't quite my experience. The registry entries are some of those set by the Personalisation csp as referenced by Personalization CSP. They seem to function on Windows 10 and 11. They force the lock screen for all users, and don't offer users any opportunity to change the lock screen.

Note the caveat:
"Personalization CSP is supported in Windows Enterprise and Education SKUs. It works in Windows Professional only when SetEduPolicies in SharedPC CSP is set, or when the device is configured in Shared PC mode with BootToCloudPCEnhanced policy."

Despite this caveat the lock screen image is forced. However, it appears to leave the original lock screen unaffected, although you can't see it. The default lock screen is Windows Spotlight, and this will continue to operate - collecting new images and occasionally putting a notification on your fixed lock screen about the new Spotlight image you can't see. You can prevent this by using the appropiate user registry entries to remove the Spotlight lock screen.

I've seen suggestions of additional registry entries to make it appear that SetEduPolicies is set. None worked for me.

Assuming you don't have an InTune/MDM setup, there are other ways of setting SetEduPolicies. The simplest way to be sure you have done this correctly is to create a Provisioning Package with Windows Configuration Designer and install it. Windows Configuration Designer - Free download and install on Windows | Microsoft Store . You need to create an advanced package.

If you do this on an otherwise unmodified Windows 10/11 Pro (I haven't tested on Home editions) and look at lock screen options, Windows Spotlight is not available. So, the lock screen default is picture and no user level action is required to keep Windows Spotlight out of the lock screen completely.

Shared PC technical reference lists additional policy settings to block some windows tips and consumer experiences that are set. These normally don't work on Pro (or Home) editions of windows, but do seem to work. I would regard both, particularly "Turn off Microsoft consumer experiences" as desirable.

There's an extra possibility for Windows 11 Pro devices. Education Policy CSP This will "declare this OS as an education environment." There are suggestions that this can be achieved by a simple registry edit:

Code:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\current\device\Education]
"IsEducationEnvironment"=dword:00000001

Elsewhere EducationSettings.IsEducationEnvironment Property (Windows.System.Profile) - Windows apps shows how to check IsEducationEnvironment is set.

This translates into Powershell as:

Code:
[Windows.System.Profile.EducationSettings, Windows.System.Profile, ContentType = WindowsRuntime]::IsEducationEnvironment

(on one line) and will show true if you have SetEduPolicies properly set On Windows 10 or 11 Pro, or IsEducationEnvironment properly set, or the registry entry in Windows 11 Pro. (no testing by me on any Home edition)

Setting the registry entry seems to be enough to enable the group policy "Turn off all Windows spotlight features" to turn off tips, Windows Spotlight on the lock screen. and the Consumer Experiences (at least at new account creation), as well as disabling Spotlight on Background, which is the only part that works on Pro. I haven't investigated this any further yet.

Clearly there is more to be said about MDM and how to apply those policies.
 

My Computers

System One System Two

  • OS
    Windows 11 25H2 Pro Build 26200
    Computer type
    PC/Desktop
    Manufacturer/Model
    MSI PRO ADL-U Cubi 5 (MS-B0A8)
    CPU
    i3-1215U
    Memory
    8GB
    Monitor(s) Displays
    Sony 43" 4k TV
    Screen Resolution
    3840x2160
    Hard Drives
    250GB NVMe M.2 PCIe Gen 3 SSD
    PSU
    External 65W
    Case
    Mini PC
    Browser
    FireFox
    Antivirus
    MS
  • Operating System
    Windows 11 Pro 25H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 3070 SFF
    CPU
    Intel i3-9100
    Memory
    16GB DDR4
    Monitor(s) Displays
    Dell S2721
    Screen Resolution
    3840 x 2160
    Hard Drives
    Samsung 500GB nvMe
    Case
    Dell small form factor
    Keyboard
    Cherry mechanical (Blue)
    Mouse
    Microsoft
    Antivirus
    MS Defender
unless you apply a reg key which specifically blocks it.
I did what you said but after that, in personalization settings it won't let the user to change the lockscreen background and says some settings are restricted by manufacturer (something like that I can't remember the exact message sorry)
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 25H2
    Computer type
    Laptop
    Manufacturer/Model
    Huawei MateBook D15
    CPU
    Ryzen 5 3500U
    Memory
    8GB
    Graphics Card(s)
    Vega 8
    Screen Resolution
    FHD
    Hard Drives
    256GB Samsung SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    ESET Smart Security Premium
  • Operating System
    Windows 10 Enterprise LTSC 21H2
    Computer type
    Laptop
    Manufacturer/Model
    MSI GS73 6RF Stealth Pro
    CPU
    intel core i7 6700HQ
    Memory
    16GB
    Graphics card(s)
    Nvidia Geforce GTX1060 (6GB)
    Screen Resolution
    FHD
    Hard Drives
    128GB SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    Windows Defender
I did what you said but after that, in personalization settings it won't let the user to change the lockscreen background and says some settings are restricted by manufacturer (something like that I can't remember the exact message sorry)
Most of the known working solutions for changing the image by script or command line depend on a GPO, or the PersonalizationCSP (which basically a GPO). The drawback is you're not allowing the user to change it again from Settings.

There's lots of other dubious "answers", which probably worked at some point but don't function uniformly on W10 & 11.

@Brink's tutorial on Change Lock Screen Background explains how to change the Lock Screen preference to Picture (as opposed to Spotlight or Slideshow). But it doesn't explain how to actually pick a different picture.

For security reasons, your lock screen image cache folder is protected by SYSTEM rights, and there's a hideous mess of reg keys that manage it. There is a WinRT API that allows you to change the image preference, and Jos Lieben provides a working script:

set-windows10LockScreen.ps1 · master · Jos / assortedFunctions · GitLab

If you remove the top section where it downloads the image file from a web source, and a line near the bottom where it removes the file at the end, then it works just fine to change the image. Note: this script only changes the image, it doesn't update the Lock Screen preference to Picture. Which @Brink's tutorial does explain.
 

My Computer

System One

  • OS
    Windows 7
@Brink's tutorial on Change Lock Screen Background explains how to change the Lock Screen preference to Picture (as opposed to Spotlight or Slideshow). But it doesn't explain how to actually pick a different picture.

Hey mate, :alien:

Sure it does. Steps 5B and 5C.

 

My Computers

System One System Two

  • OS
    Windows 11 Pro for Workstations
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom self build
    CPU
    Intel i7-8700K 5 GHz
    Motherboard
    ASUS ROG Maximus XI Formula Z390
    Memory
    64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz (F4-3600C18D-32GTZR)
    Graphics Card(s)
    ASUS ROG-STRIX-GTX1080TI-O11G-GAMING (11GB GDDR5X)
    Sound Card
    Integrated Digital Audio (S/PDIF)
    Monitor(s) Displays
    2 x Samsung Odyssey G75 27"
    Screen Resolution
    2560x1440
    Hard Drives
    1TB Samsung 990 PRO M.2,
    4TB Samsung 990 PRO M.2,
    TerraMaster F8 SSD Plus NAS
    PSU
    Seasonic Prime Titanium 850W
    Case
    Thermaltake Core P3 wall mounted
    Cooling
    Corsair Hydro H115i
    Keyboard
    Amazon Basics Wired Full Keyboard MD005
    Mouse
    Logitech MX Master 4
    Internet Speed
    2 Gbps Download and 100 Mbps Upload
    Browser
    Chrome and Edge
    Antivirus
    Microsoft Defender
    Other Info
    Logitech Z625 speaker system,
    Logitech BRIO 4K Pro webcam,
    HP Color LaserJet Pro MFP M477fdn,
    CyberPower CP1500PFCLCD
    Galaxy S23 Plus phone
  • Operating System
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    Surface Laptop 7 Copilot+ PC
    CPU
    Snapdragon X Elite (12 core) 3.42 GHz
    Memory
    16 GB LPDDR5x-7467 MHz
    Monitor(s) Displays
    15" HDR
    Screen Resolution
    2496 x 1664
    Hard Drives
    1 TB SSD
    Internet Speed
    Wi-Fi 7 and Bluetooth 5.4
    Browser
    Chrome and Edge
    Antivirus
    Microsoft Defender
Doesn't look like a script or command to me... @Sheikh's building install images, so he needs a script.
But I did use your tutorial for the three common reg keys.

Code:
Set-LockScreen.ps1 -Spotlight
Set-LockScreen.ps1 -Picture -FileName background.jpg
Set-LockScreen.ps1 -Slideshow
 

Attachments

Last edited:

My Computer

System One

  • OS
    Windows 7
Doesn't look like a script or command to me... @Sheikh's building install images, so he needs a script.
But I did use your tutorial for the three common reg keys.

Code:
Set-LockScreen.ps1 -Spotlight
Set-LockScreen.ps1 -Picture -FileName background.jpg
Set-LockScreen.ps1 -Slideshow
Thanks dear garlin. ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️ ❤️
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 25H2
    Computer type
    Laptop
    Manufacturer/Model
    Huawei MateBook D15
    CPU
    Ryzen 5 3500U
    Memory
    8GB
    Graphics Card(s)
    Vega 8
    Screen Resolution
    FHD
    Hard Drives
    256GB Samsung SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    ESET Smart Security Premium
  • Operating System
    Windows 10 Enterprise LTSC 21H2
    Computer type
    Laptop
    Manufacturer/Model
    MSI GS73 6RF Stealth Pro
    CPU
    intel core i7 6700HQ
    Memory
    16GB
    Graphics card(s)
    Nvidia Geforce GTX1060 (6GB)
    Screen Resolution
    FHD
    Hard Drives
    128GB SSD + 1TB HDD
    Browser
    Microsoft Edge
    Antivirus
    Windows Defender
I think that the origin of the WinRT API based script is here: Setting the lock screen background with PowerShell. A little more explanation here: Awaiting WinRT's IAsyncAction in PowerShell

To see the horrible hacks that we used to do, look at the history of Jos Lieben's script (first commit / test). I can remember doing this on Windows 10. I also tried the NoChangingLockScreen policy. It disables the interface in Settings, but doesn't prevent users from changing the lock screen type with registry edits described by @Brink
 

My Computers

System One System Two

  • OS
    Windows 11 25H2 Pro Build 26200
    Computer type
    PC/Desktop
    Manufacturer/Model
    MSI PRO ADL-U Cubi 5 (MS-B0A8)
    CPU
    i3-1215U
    Memory
    8GB
    Monitor(s) Displays
    Sony 43" 4k TV
    Screen Resolution
    3840x2160
    Hard Drives
    250GB NVMe M.2 PCIe Gen 3 SSD
    PSU
    External 65W
    Case
    Mini PC
    Browser
    FireFox
    Antivirus
    MS
  • Operating System
    Windows 11 Pro 25H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 3070 SFF
    CPU
    Intel i3-9100
    Memory
    16GB DDR4
    Monitor(s) Displays
    Dell S2721
    Screen Resolution
    3840 x 2160
    Hard Drives
    Samsung 500GB nvMe
    Case
    Dell small form factor
    Keyboard
    Cherry mechanical (Blue)
    Mouse
    Microsoft
    Antivirus
    MS Defender
Doesn't look like a script or command to me... @Sheikh's building install images, so he needs a script.
But I did use your tutorial for the three common reg keys.

Code:
Set-LockScreen.ps1 -Spotlight
Set-LockScreen.ps1 -Picture -FileName background.jpg
Set-LockScreen.ps1 -Slideshow
Thanks for sharing the script. I tested it out. Setting slideshow and spotlight works on Win11 24H2. However, I can't get it to set to picture and get the error message "Failed to set Lock Screen image". Any idea how I can resolve it? I'm using a jpg as the background image.
 

My Computer

System One

  • OS
    windows 11
    Computer type
    Laptop
Is there something special about your background image? How big is it (dimension and file size)? Have you tried other images?

Since you didn't get a "Failed to load image from [path]" error, the image was loaded from the filesystem. The script was written and tested on 24H2.
 

My Computer

System One

  • OS
    Windows 7
Here's another possibility. Although I suspect that @garlin suggestions are more likely to help.

The windows runtime api contains 2 methods for setting the users lock screen Windows.System.UserProfile Namespace - Windows apps . The second method (not used in @garlin script): UserProfilePersonalizationSettings.TrySetLockScreenImageAsync Method (Windows.System.UserProfile) - Windows apps contains a note:

When you set an image more than once, the new image file must have a different name than the previously set image. If you set a new image using a file with the same name as the previous image, it will fail.

storage file objects have a name and a path property, so I assume this refers to the name only. So, try a different name for your lock screen image.
 

My Computers

System One System Two

  • OS
    Windows 11 25H2 Pro Build 26200
    Computer type
    PC/Desktop
    Manufacturer/Model
    MSI PRO ADL-U Cubi 5 (MS-B0A8)
    CPU
    i3-1215U
    Memory
    8GB
    Monitor(s) Displays
    Sony 43" 4k TV
    Screen Resolution
    3840x2160
    Hard Drives
    250GB NVMe M.2 PCIe Gen 3 SSD
    PSU
    External 65W
    Case
    Mini PC
    Browser
    FireFox
    Antivirus
    MS
  • Operating System
    Windows 11 Pro 25H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Optiplex 3070 SFF
    CPU
    Intel i3-9100
    Memory
    16GB DDR4
    Monitor(s) Displays
    Dell S2721
    Screen Resolution
    3840 x 2160
    Hard Drives
    Samsung 500GB nvMe
    Case
    Dell small form factor
    Keyboard
    Cherry mechanical (Blue)
    Mouse
    Microsoft
    Antivirus
    MS Defender
The only instance where someone reported the script failing, they were trying to import a 40MB PNG file at 8K resolution.

WinRT API is doing the usual transcoding of the wallpaper to the cached image folder. So massive images may overwhelm it. There are techniques to bypass the transcoding (to prevent recompression artifacts), but you end up having to do some TrustedInstaller or takeown hacks to install your file.
 

My Computer

System One

  • OS
    Windows 7
Is there something special about your background image? How big is it (dimension and file size)? Have you tried other images?

Since you didn't get a "Failed to load image from [path]" error, the image was loaded from the filesystem. The script was written and tested on 24H2.
So I test on PC and it work fine. The file size is 600K.

It failed due to some system corruption in his PC. So I re-intall Windows and the script works. Thanks for your help.
 

My Computer

System One

  • OS
    windows 11
    Computer type
    Laptop

Latest Support Threads

Back
Top Bottom