Windows XP Random Logon Background (Wallpaper)

A script that sets a random logon background on every boot.


The appearance of the logon screen is defined in the registry under HKEY_USERS.DEFAULTControl PanelDesktop and HKEY_USERS.DEFAULTControl PanelColors (and maybe other places). The procedure described here modifies four keys, which set the path to the desired wallpaper, setup how the wallpaper is positioned and scaled and what the background colour should be.

The procedure involves Linux (or, more precisely, a bash shell) in order to create a .BAT (batch) file for Windoze, which will setup the random image.

The wallpaper (background) images must be in .BMP format.


Prepare a working directory

template.r-e-g: (adjust C:\GGLBG\ to suit your target directory on the windows machine).

Windows Registry Editor Version 5.00

[HKEY_USERS.DEFAULTControl PanelDesktop]

[HKEY_USERS.DEFAULTControl PanelColors]
"Background"="0 0 0" (again, adjust C:\GGLBG\):

rm -f *.reg
for X in *.bmp; do
    n=`printf %05i $i`
    cp template.r-e-g $r
    sed -i "s/XXXXX/$X/" $r
echo "@echo off" > RANDIMG.BAT
echo "set /a x=%random%*$i/32767+1" >> RANDIMG.BAT
for ((j=1;j<=i;j++)); do
    echo "IF %x% == $j GOTO $j" >> RANDIMG.BAT
echo "GOTO end" >> RANDIMG.BAT
for ((j=1;j<=i;j++)); do
    n=`printf %05i $j`
    echo ":$j" >> RANDIMG.BAT
    echo "regedit -s C:\GGLBG\${n}.reg" >> RANDIMG.BAT
    echo "GOTO end" >> RANDIMG.BAT
echo ":end" >> RANDIMG.BAT
unix2dos RANDIMG.BAT
echo "done."
# eof

Run the script will create a .reg (registry) file for each .bmp found in the directory. It will then create a batch file (RANDIMG.BAT), which, when called, will setup one of the images as the logon wallpaper.

Copy the files to the windows machine

Copy the files in the working directory to the target directory on the windows machine (in this example: C:GGLBG).

Setup windows to run the script at shutdown

Use the group policy editor (GPEDIT.MSC) to setup a shutdown script (Computer configuration/Windows settings/Scripts). Add the RANDIMG.BAT to the list.


..and enjoy.