# Script to set lock screen background for Windows device

Organizations often need to standardize the appearance of their devices with their branding logo or to display important information. For a lock screen background, organizations can set an image with any information, for instance, any information that can be helpful if the device gets lost. This can be done by deploying a script, allowing administrators to choose an image to set lock screen background on Windows devices remotely. Using Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) action, IT admins can execute the script to set the lock screen background on Windows devices.

 Note: 
The script is supported on Windows 10 and 11 devices.

 

 Disclaimer: 
The sample script provided below are adapted from third-party open source sites.

 

PowerShell script to set lock screen background
-----------------------------------------------

PowerShell script to set lock screen on Windows devices

\# Define the parent registry path $parentRegistryPath = "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP" # Define the name and value $keyName = "LockScreenImagePath" $imagePath = "C:\\Path\\to\\the\\file" # Create the registry key New-Item -Path $parentRegistryPath -Name $keyName -Force # Set the registry key value Set-ItemProperty -Path "$parentRegistryPath" -Name $keyName -Value $imagePath 

   1

2

3

4

5

6

7

8

9

10

11

12

  \# Define the parent registry path 

$parentRegistryPath = "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP"

\# Define the name and value 

$keyName = "LockScreenImagePath"

$imagePath = "C:\\Path\\to\\the\\file"

\# Create the registry key 

New-Item -Path $parentRegistryPath -Name $keyName -Force

\# Set the registry key value 

Set-ItemProperty -Path "$parentRegistryPath" -Name $keyName -Value $imagePath 

   

 

  

This PowerShell script creates and modifies a registry key within **‘HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP’**. The script defines the names of corresponding values for the registry key. The variable $keyName is set to **‘LockScreenImagePath’**, which is the name of the key in the registry. Replace the actual path of the image file in the place of **‘C:\\Path\\to\\the\\file’**.

The New-Item cmdlet is used to create a new registry key at the specified path, with -Force ensuring that any existing item with the same name is overwritten. **Set-ItemProperty** cmdlet sets the value of the newly created registry key to the specified image path.

Batch script to set lock screen background
------------------------------------------

Batch script to set lock screen on Windows devices

@echo off setlocal ::Define the parent registry path set parentRegistryPath=HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP ::Define the name and value set keyName=LockScreenImagePath set imagePath= C:\\Path\\to\\the\\file ::Create the registry key reg add "%parentRegistryPath%" /v "%keyName%" /t REG\_SZ /d "%imagePath%" /f ::Check if the operation was successful if %errorlevel% equ 0 ( echo Registry key added successfully. ) else ( echo Failed to add registry key. ) endlocal 

   1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

  @echo off 

setlocal

::Define the parent registry path 

set parentRegistryPath=HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP

::Define the name and value 

set keyName=LockScreenImagePath 

set imagePath= C:\\Path\\to\\the\\file

::Create the registry key 

reg add "%parentRegistryPath%" /v "%keyName%" /t REG\_SZ /d "%imagePath%" /f

::Check if the operation was successful 

if %errorlevel% equ 0 (

 echo Registry key added successfully.

) else (

 echo Failed to add registry key.

)

endlocal 

   

 

  

The Batch script works much in a way similar to the PowerShell script.

After executing the script, [restart](https://www.hexnode.com/mobile-device-management/help/restart-a-device-using-hexnode-mdm/) the Windows device for the changes to occur. The scripts also restrict the user from changing the lock screen.

You can verify the output of the script by navigating to the **Action History** tab.

[![Verify the output of the script to set lock screen background from the Hexnode UEM console](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/06/Execute-a-PowerShell-script-to-set-lock-screen-background.png "Execute a PowerShell script to set lock screen background")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/06/Execute-a-PowerShell-script-to-set-lock-screen-background.png)

 Notes:- The lock screen will have a dark background if the image file path doesn’t exist on the device.
- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.