Windows – How to set the desktop background on Windows from a script

desktop-customizationscriptwindowswindows xp

On X Windows I had a cool 'silent-alarm" reminder script that would change my root window (background) color to solid red, just for a few seconds a few moments before changing it back. Is there a way to do this for Windows XP?

I'm thinking some kind of scheduled task that uses cscript to set registry keys (HKEY_CURRENT_USER\Control Panel\Desktop) . However my attempts don't seem to have any effect. What do I have to signal to read those registry entries and re-draw the desktop?

Best Answer

This does change the background via command line. Just save this as a bat file. Use bmp or you will have to refresh. Also sets the wallpaper to be stretched. If you take out the wallpaperstyle line it will automatically be centered.

@echo off
reg add "HKCU\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f 
reg add "HKCU\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\[LOCATION OF WALLPAPER HERE]" /f 
reg delete "HKCU\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperStyle /f
reg add "HKCU\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters 
exit