Skip to main content

How to Get and Set Screen Saver Settings in Batch Script

Managing screen saver settings is a common requirement in corporate environments or retail deployments where specific security and display policies must be enforced. Whether you need to ensure a secure password lock activates after a certain period of inactivity or simply want to brand a presentation kiosk with a company logo screen saver, automating these configurations via Batch Script is highly effective.

In this guide, we will explore the registry keys that control Windows screen saver behavior and how to read (get) and modify (set) them programmatically.

Understanding the Screen Saver Registry Keys

Windows stores the current user's screen saver preferences in the registry under the Desktop key. There are four primary values you need to be aware of:

HKCU\Control Panel\Desktop
Value NameTypeDescription
SCRNSAVE.EXEREG_SZThe full path to the .scr screen saver file. If this value is missing or empty, the screen saver is disabled.
ScreenSaveActiveREG_SZ1 = Screen saver is active. 0 = Disabled.
ScreenSaveTimeOutREG_SZThe idle time in seconds before the screen saver starts (e.g., 600 for 10 minutes).
ScreenSaverIsSecureREG_SZ1 = Requires a password to unlock. 0 = No password required.
info

Even though these values handle numbers (like seconds or booleans), they are stored as REG_SZ (strings), not REG_DWORD. Always use the REG_SZ type when setting them.

Method 1: Getting Current Screen Saver Settings

To read the current configuration, we use the REG QUERY command and extract the relevant data.

@echo off
setlocal enabledelayedexpansion

echo Reading Current Screen Saver Settings...
echo ========================================

:: Read the active status
set "ss_active="
for /f "tokens=2*" %%A in ('reg query "HKCU\Control Panel\Desktop" /v ScreenSaveActive 2^>nul ^| find "ScreenSaveActive"') do set "ss_active=%%B"
if "!ss_active!"=="1" (echo Active: YES) else (echo Active: NO)

:: Read the executable path
set "ss_exe="
for /f "tokens=2*" %%A in ('reg query "HKCU\Control Panel\Desktop" /v SCRNSAVE.EXE 2^>nul ^| find "SCRNSAVE"') do set "ss_exe=%%B"
if defined ss_exe (echo File: !ss_exe!) else (echo File: None)

:: Read the timeout
set "ss_time="
for /f "tokens=2*" %%A in ('reg query "HKCU\Control Panel\Desktop" /v ScreenSaveTimeOut 2^>nul ^| find "ScreenSaveTimeOut"') do set "ss_time=%%B"
if defined ss_time (
set /a "mins=ss_time / 60"
echo Wait: !ss_time! seconds [!mins! minutes]
) else (
echo Wait: Not Set
)

:: Read the secure lock status
set "ss_secure="
for /f "tokens=2*" %%A in ('reg query "HKCU\Control Panel\Desktop" /v ScreenSaverIsSecure 2^>nul ^| find "ScreenSaverIsSecure"') do set "ss_secure=%%B"
if "!ss_secure!"=="1" (echo Secure: YES [Password Required]) else (echo Secure: NO)

echo.
pause

Understanding the Loop

The for /f loop parses the output of reg query, which returns lines containing the value name, type, and data. By piping through find, we isolate only the line containing our target value name, avoiding header or blank lines that could produce false matches. The tokens=2* option captures the data portion (skipping the value name and type columns). The 2^>nul suppresses the standard error output in case the key hasn't been created yet (for example, on a brand-new user profile).

Method 2: Setting the Screen Saver and Timeout

To enforce a specific screen saver, we use the REG ADD command to modify the values in the Desktop key.

Example: Setting the "Mystify" Screen Saver

This script activates the built-in "Mystify" screen saver, sets the timeout to 15 minutes (900 seconds), and ensures the workstation locks upon resume.

@echo off
setlocal

echo Applying Corporate Screen Saver Policy...

set "reg_key=HKCU\Control Panel\Desktop"
set "scr_file=C:\Windows\System32\Mystify.scr"
set "timeout=900"

:: Verify the screen saver file exists
if not exist "%scr_file%" (
echo [ERROR] Screen saver file not found: %scr_file%
pause
exit /b 1
)

:: 1. Set the screen saver program
REG ADD "%reg_key%" /v SCRNSAVE.EXE /t REG_SZ /d "%scr_file%" /f >nul

:: 2. Enable the screen saver
REG ADD "%reg_key%" /v ScreenSaveActive /t REG_SZ /d "1" /f >nul

:: 3. Set timeout (seconds)
REG ADD "%reg_key%" /v ScreenSaveTimeOut /t REG_SZ /d "%timeout%" /f >nul

:: 4. Enable password lock
REG ADD "%reg_key%" /v ScreenSaverIsSecure /t REG_SZ /d "1" /f >nul

echo [OK] Screen saver set to Mystify (15 minutes, Secured^).

:: 5. Tell the system to reload screen saver settings
powershell -noprofile -command "Add-Type -Name 'SPI' -Namespace 'Win32' -MemberDefinition '[DllImport(\"user32.dll\")] public static extern bool SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);'; [Win32.SPI]::SystemParametersInfo(17, 1, $null, 2) | Out-Null"

echo [OK] Settings applied immediately.
pause

How the API Refresh Works

If you modify the registry but do not notify the system, Windows will not actually honor the new screen saver settings until you log off and log back in. To make the settings take effect immediately, we call the SystemParametersInfo API via an embedded PowerShell block.

  • 17 is the code for SPI_SETSCREENSAVEACTIVE.
  • The second parameter (1) tells the system to enable the screen saver (use 0 to disable).
  • 2 (SPIF_SENDCHANGE) tells Windows to update the user profile and broadcast the change to all windows.

Method 3: Disabling the Screen Saver Completely

For presentations, gaming, or kiosk setups where the screen must stay awake indefinitely, disabling the screen saver is necessary.

@echo off
setlocal

echo Disabling Screen Saver...

set "reg_key=HKCU\Control Panel\Desktop"

:: Set Active to 0
REG ADD "%reg_key%" /v ScreenSaveActive /t REG_SZ /d "0" /f >nul

:: Delete the EXE reference entirely
REG DELETE "%reg_key%" /v SCRNSAVE.EXE /f >nul 2>&1

:: Refresh settings instantly (parameter 0 = disable)
powershell -noprofile -command "Add-Type -Name 'SPI' -Namespace 'Win32' -MemberDefinition '[DllImport(\"user32.dll\")] public static extern bool SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);'; [Win32.SPI]::SystemParametersInfo(17, 0, $null, 2) | Out-Null"

echo [OK] Screen Saver disabled.
pause

Common Mistakes

The Wrong Way: Using REG_DWORD for Timeout

:: WRONG - The value must be a string (REG_SZ)
REG ADD "HKCU\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_DWORD /d 600 /f

Output Concern: While it makes logical sense for numbers to be DWORDs, the legacy Windows Control Panel expects ScreenSaveTimeOut and ScreenSaverIsSecure to be REG_SZ (strings). Writing a DWORD may cause the Windows GUI to crash or ignore the setting entirely.

The Wrong Way: Forgetting the API Refresh

:: WRONG - Settings will not apply until reboot
REG ADD "HKCU\Control Panel\Desktop" /v ScreenSaveActive /t REG_SZ /d "1" /f
echo Done.

If you modify the registry but fail to trigger the SystemParametersInfo API via the embedded PowerShell, the screen saver will not activate at the new timeout.

Best Practices

  1. Always use REG_SZ: Despite representing numbers or boolean logic, the screen saver system reads strings.
  2. Verify the .scr file exists: Before enforcing a custom screen saver, ensure the file actually exists on the target machine to prevent a broken experience.
  3. Include the API refresh block: It is mandatory for live deployments. A script that requires a reboot simply to turn on the screen saver is poorly designed.

Working with Group Policy (Enterprise Networks)

While Batch Scripts are excellent for standalone workstations, in an Active Directory environment, screen saver settings are almost exclusively managed via Group Policy Objects (GPO).

GPO settings are stored in HKCU\Software\Policies\Microsoft\Windows\Control Panel\Desktop. If a GPO is actively enforcing these values, any changes your Batch script makes to the standard HKCU\Control Panel\Desktop key will be ignored, and the GUI will be grayed out. If you are an administrator writing a local script and the settings aren't applying, check if a domain policy is overriding you.

Conclusion

Getting and setting screen saver parameters in Batch Script is managing four distinct registry string values inside the HKCU\Control Panel\Desktop key. Whether you are retrieving the current timeout, deploying a custom .scr executable, or disabling the feature outright for a digital sign, the REG command provides full control. Crucially, calling the SystemParametersInfo API via PowerShell immediately afterward bridges the gap between editing the registry and actually instructing the operating system to honor the new configuration.