Change the lock screen with a cmd command

OB7523 -  
 OB7523 -

Hello,

I am part of a computer club with about ten PCs.

I would like to change the Windows 10/11 lock screen image via the command line.

Thank you.

Ob


6 answers

steph810 Posted messages 1864 Registration date   Status Member Last intervention   152
 

Hello, do you want to change just the lock screen or also the wallpaper?

I have a script that works on Windows 11 for changing the lock screen and the wallpaper.

https://www.youtube.com/watch?v=BV1obmZmctc&feature=youtu.be

Just to clarify, the video is unlisted, not public; only those with the link can view it, just in case a mod.... :)

After this, it will be modified if you only need the lock screen.

0
steph810 Posted messages 1864 Registration date   Status Member Last intervention   152
 

here is only for lock screen a code to save as powershell extension .ps1:

You just need to modify line 3 with the path of the file.

#Path of the images ex: "https://mysite.core.windows.net/w" $LockScreenSource = "C:\Users\tech\Downloads\330.png" ################################################################ if (-not [string]::IsNullOrWhiteSpace($LogPath)) { Start-Transcript -Path "$($LogPath)\$($env:COMPUTERNAME).log" | Out-Null } $ErrorActionPreference = "Stop" $RegKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" $LockScreenPath = "LockScreenImagePath" $LockScreenStatus = "LockScreenImageStatus" $LockScreenUrl = "LockScreenImageUrl" $StatusValue = "1" $LockScreenImageValue = "C:\Windows\System32\oobe\LockScreen.jpg" if (!$LockScreenSource -and !$BackgroundSource) { Write-Host "Lock screen and background must have a value." } else { if(!(Test-Path $RegKeyPath)) { Write-Host "Creating a registry path $($RegKeyPath)." New-Item -Path $RegKeyPath -Force | Out-Null } if ($LockScreenSource) { Write-Host "Copying lock image from $($LockScreenSource) to $($LockScreenImageValue)." (New-Object System.Net.WebClient).DownloadFile($LockScreenSource, "$LockScreenImageValue") Write-Host "Creating an entry in the registry for lock screen" New-ItemProperty -Path $RegKeyPath -Name $LockScreenStatus -Value $StatusValue -PropertyType DWORD -Force | Out-Null New-ItemProperty -Path $RegKeyPath -Name $LockScreenPath -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null New-ItemProperty -Path $RegKeyPath -Name $LockScreenUrl -Value $LockScreenImageValue -PropertyType STRING -Force | Out-Null } } if (-not [string]::IsNullOrWhiteSpace($LogPath)){Stop-Transcript}
0
Didi64_549 Posted messages 2789 Registration date   Status Member Last intervention  
 

Hello,

See this towards the bottom of the page:

https://www.ionos.fr/digitalguide/serveur/know-how/commande-cmd/


0
bazfile Posted messages 58481 Registration date   Status Moderator Last intervention   20 264
 

Hello.

Change-lock-screen-image-windows-10-11-solutions.


bazfile
Moderator/Security Contributor.
A hello, an answer, a thank you are always appreciated.

0
steph810 Posted messages 1864 Registration date   Status Member Last intervention   152
 

yes, but since it's for a computer room, he wants "I think" something automated to save time; if he has more than 10 PCs to do, it quickly gets long and tedious.

0
brucine Posted messages 24677 Registration date   Status Member Last intervention   4 146 > steph810 Posted messages 1864 Registration date   Status Member Last intervention  
 

Hello,

We will have the same issue with your script unless we deploy it on all machines via GPO, NETUSE or whatever we want.

0
steph810 Posted messages 1864 Registration date   Status Member Last intervention   152 > brucine Posted messages 24677 Registration date   Status Member Last intervention  
 

What do you mean? Just a USB stick, run the script on each workstation and it's done.

It saves going into all the menus.

0
brucine Posted messages 24677 Registration date   Status Member Last intervention   4 146 > steph810 Posted messages 1864 Registration date   Status Member Last intervention  
 

It's the same thing: not sure we saved time compared to the graphical manipulation, especially since the line

 "C:\Users\tech\Downloads\330.png"

is infected: the user is not the same on each workstation, and even if it were, the image file needs to be copied to that location on each PC.

The 2 issues can be resolved quite easily, but by modifying the script to:

%HOMEPATH%\Downloads\330.png

and by copying the image file to the USB drive before moving it, so that either this script can be launched from the USB drive after going to the drive letter and then using %~dp0, or by adding to the script one that identifies the drive letter upon connection.

Otherwise, we will have to copy this image manually and in any case perform the operation 10 times.

0
OB7523
 

Hello,

Thank you for your many responses, but it’s not quite what I’m looking for.

As I said: 10 PCs and 6 sessions per PC (one per day of the week except Sunday).

I was thinking of a .BAT file to run on a USB drive.

- Copy the club logo to C: with the Copy command.

- Set it as wallpaper with: reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d C:\01.jpg

- Set it as the lock screen, but I don’t know the command for that???

Thanks if you have any ideas...

OB

0
bazfile Posted messages 58481 Registration date   Status Moderator Last intervention   20 264
 

Rather ask this question in this forum https://forums.commentcamarche.net/forum/programmation-3

0
brucine Posted messages 24677 Registration date   Status Member Last intervention   4 146
 

Your question is still not very clear.

The username, if it changes daily, is not relevant since it can simply be referred to as I mentioned by %HOMEPATH% for the wallpaper, and the lock screen is a system-wide setting independent of the user.

The first can be obtained as you noted by a REG ADD syntax; for the second, a somewhat convoluted PowerShell syntax was proposed because the result can also be achieved via a REG syntax as indicated here at the bottom of the thread.
https://techcommunity.microsoft.com/t5/windows-powershell/editing-lockscreen-with-script-via-registry/m-p/1652851

Should we have a different image for each day of the week, and this every week of the year?

In this case, the situation will be a bit more complicated; it would be easier to copy once for all 6 images (of course in a folder independent of the user), but we would need to make a conditional statement in the batch on the day of the week to choose the image and overwrite the previous one using REG ADD /F.

Can you clarify what you want to do?

0
OB7523
 

Hello,

what I want to do is put the club's logo on all sessions of all PCs.

For example: on Monday, when a member turns on the PC, they have the club's logo displayed on the login screen and then as the wallpaper. This for all sessions of all PCs.

Thank you.

Ob

0
bazfile Posted messages 58481 Registration date   Status Moderator Last intervention   20 264
 

Repetita iuvant:

Rather ask this question in this forum https://forums.commentcamarche.net/forum/programmation-3

0
brucine Posted messages 24677 Registration date   Status Member Last intervention   4 146
 

It is generally resolved by a simple batch but launched as an administrator from the key if other screen conditions are not set on the PCs (Windows in the lead...), which is why the classic approach is more towards GPO or a Tweaker like Winaero Tweaker set up on each PC.

I'm not sure that the lock screen format must necessarily be jpg, in which case the image will need to be copied in 2 different formats.

 

@echo off IF NOT EXIST C:\mon_image.bmp COPY mon_image.bmp C:\mon_image.bmp reg add "HKCU\Control Panel\Desktop" /v Wallpaper /d "C:\mon_image.bmp" /F RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True reg add HKLM\Software\Policies\Microsoft\Windows\Personalization /v LockScreenImage /t REG_SZ /d "C:\mon_image.bmp" /f :EOF
0
OB7523
 

OK!

Thank you...

Ob

0