Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for setwallp.bat

(view source code of setwallp.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: Check number of command line arguments
  6. IF     "%~1"==""            GOTO Syntax
  7. IF NOT "%~2"==""            GOTO Syntax
  8.  
  9. :: Check if invalid characters were used
  10. ECHO.%* | FIND "/" > NUL && GOTO Syntax
  11. ECHO.%* | FIND "?" > NUL && GOTO Syntax
  12. ECHO.%* | FIND "*" > NUL && GOTO Syntax
  13.  
  14. :: Get the fully qualified path and check if the file exists
  15. PUSHD %windir%
  16. IF NOT EXIST "%~1"          GOTO Syntax
  17. DIR /A-D "%~1" >NUL 2>&1 || GOTO Syntax
  18. SET WallPaper=%~f1
  19. POPD
  20.  
  21. :: Escape backslashes for the temporary .REG file
  22. SET WallPaper=%WallPaper:\=\\%
  23.  
  24. :: Create a temporary .REG file to change the Wallpaper setting
  25. >  "%Temp%.\wallpaper.reg" ECHO REGEDIT4
  26. >> "%Temp%.\wallpaper.reg" ECHO.
  27. >> "%Temp%.\wallpaper.reg" ECHO [HKEY_CURRENT_USER\Control Panel\Desktop]
  28. >> "%Temp%.\wallpaper.reg" ECHO "Wallpaper"="%WallPaper%"
  29. >> "%Temp%.\wallpaper.reg" ECHO.
  30.  
  31. :: Merge the temporary file to change the Wallpaper setting in the registry
  32. START /WAIT REGEDIT.EXE /S "%Temp%.\wallpaper.reg"
  33.  
  34. :: Activate the changes; thanks for Pete Smith for this RUNDLL32 command
  35. :: RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
  36. RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1 True
  37.  
  38. :: Clean up
  39. SET WallPaper=
  40. DEL "%Temp%.\wallpaper.reg"
  41.  
  42. :: Done
  43. GOTO:EOF
  44.  
  45.  
  46. :Syntax
  47. ECHO.
  48. ECHO SetWallp.bat,  Version 1.00 for Windows 2000 and later
  49. ECHO Set a specified bitmap as Windows' wallpaper.
  50. ECHO Based on a RUNDLL32 command by Pete Smith.
  51. ECHO.
  52. ECHO Usage:  SETWALLP  bitmap
  53. ECHO.
  54. ECHO Where:  "bitmap"  is the bitmap file
  55. ECHO         (or the fully qualified path if not located in %windir%)
  56. ECHO.
  57. ECHO Written by Rob van der Woude
  58. ECHO http://www.robvanderwoude.com
  59.  

page last modified: 2024-04-16; loaded in 0.0050 seconds