Category filter
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 action, IT admins can execute the script to set the lock screen background on Windows devices.
PowerShell script to set lock screen background
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
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 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.