(view source code of wallpapr.bat as plain text)
@ECHO OFF
IF NOT "%OS%"=="Windows_NT" (
ECHO.
ECHO This batch file will only work on Windows 2000 and later.
GOTO Syntax
)
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 (
ECHO.
ECHO This batch file will only work on Windows 2000 and later.
GOTO Syntax
)
FINDSTR.EXE /? >NUL 2>&1
IF ERRORLEVEL 1 (
ECHO.
ECHO FINDSTR.EXE not found
GOTO Syntax
)
IF NOT "%~2"=="" GOTO Syntax
ECHO "%~1" | FIND "?" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
ECHO "%~1" | FIND "/" >NUL
IF NOT ERRORLEVEL 1 GOTO Syntax
SETLOCAL
:: Define direcory where bitmaps are located
SET WorkingDir=%~1
IF NOT DEFINED WorkingDir SET WorkingDir=%windir%
:: Count number of read-only bitmap files
FOR /F "tokens=1 delims=:" %%A IN ('ATTRIB.EXE "%WorkingDir%.\*.bmp" 2^>NUL ^| FINDSTR.EXE /R /B /C:".....R" ^| FINDSTR.EXE /N "R"') DO SET NumPics=%%A
IF NOT DEFINED NumPics (
ECHO.
ECHO No read-only bitmap files found in %WorkingDir%
GOTO Syntax
)
:: Calculate random to number of bitmaps factor
SET /A Factor = 32768 / %NumPics%
:: Make variable Random really random by using a more or less random "seed"
FOR /F "tokens=* delims=" %%A IN ('VER ^| TIME ^| FINDSTR.EXE /R /C:"[0-9]"') DO SET TimeStr=%%A
SET TimeStr=%TimeStr::= %
SET TimeStr=%TimeStr:.= %
SET TimeStr=%TimeStr:,= %
FOR %%A IN (%TimeStr%) DO SET Seed=%%A
SET /A Seed = %Seed% + 2
FOR /L %%A IN (0,1,%Seed%) DO CALL SET Dummy=%%Random%%
:Again
:: Select a random bitmap from the "array"
SET /A PicsIndex = %Random% / %Factor% + 1
:: Force a new selection on array out of bound errors
IF %PicsIndex% GTR %NumPics% GOTO Again
IF %PicsIndex% LSS 1 GOTO Again
:: Make the randomly selected bitmap file the current user's wallpaper
FOR /F "tokens=1* delims=:" %%A IN ('ATTRIB.EXE %WorkingDir%.\*.bmp ^| FINDSTR.EXE /R /B /C:".....R" ^| FINDSTR.EXE /N "R"') DO (
IF %PicsIndex% EQU %%A CALL :MakeWallpaper "%%~B"
)
ENDLOCAL
GOTO:EOF
:MakeWallpaper
:: Extract bitmap file name from line
SET PicsChoice=%~1
SET PicsChoice=%PicsChoice:~11%
:: Display wallpaper file name
ECHO New wallpaper bitmap: %PicsChoice%
:: Create, merge and then delete temporary REG file
:: to change the Wallpaper setting in the registry
SET PicsChoice=%PicsChoice:\=/%
SET PicsChoice=%PicsChoice:/=\\%
> "%Temp%.\wallpaper.dat" ECHO REGEDIT4
>> "%Temp%.\wallpaper.dat" ECHO.
>> "%Temp%.\wallpaper.dat" ECHO [HKEY_CURRENT_USER\Control Panel\Desktop]
>> "%Temp%.\wallpaper.dat" ECHO "Wallpaper"="%PicsChoice%"
>> "%Temp%.\wallpaper.dat" ECHO.
START /WAIT REGEDIT.EXE /S "%Temp%.\wallpaper.dat"
DEL "%Temp%.\wallpaper.dat"
:: Activate the changes; thanks for Pete Smith for this RUNDLL32 command
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
GOTO:EOF
:Syntax
ECHO.
ECHO Wallpapr.bat, Version 1.00 for Windows 2000 and later
ECHO Randomly change Windows' background bitmap
ECHO.
ECHO Usage: WALLPAPR [ working_dir ]
ECHO.
ECHO Where: "working_dir" is the directory where the bitmap files
ECHO are located (default: %Windir%)
ECHO.
ECHO Note: Each time this batch file is run, a random selection
ECHO will be made from a list of READ-ONLY bitmap files
ECHO in the working directory.
ECHO.
ECHO Based on a RUNDLL32 command by Pete Smith
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
page last modified: 2024-04-16; loaded in 0.0103 seconds