24

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?

3

10 Answers 10

11

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 
5
  • 1
    You might have to remove HKCU\Control Panel\Desktop\TranscodedImageCache before updating. Commented Nov 10, 2017 at 21:52
  • Does the wallpaper have to be on the local computer or can it be on a different computer on the network like \\server\share\wallpaper.bmp? Commented Dec 21, 2019 at 23:46
  • UpdatePerUserSystemParameters was never designed to be called by rundll32 and if it works or not is undefined behavior. Commented May 3, 2022 at 12:48
  • It seems you should change file name each time... Commented Feb 8, 2023 at 15:29
  • Is there something similar that would change the DIR for a slideshow? Commented Aug 2, 2023 at 10:59
7

I think that once you modify the wallpaper setting in the registry, you simply need to run

RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters 

from the command line and the changes should take effect. You need to make sure that your image is a bmp file.

In fact, I just tried this by creating a desktop sized bmp file that was all red. I changed the //HKCU/control panel/desktop/wallpaper key to contain the full pathname to this bitmap. I ran the above command from the command line and the desktop changed to the red bmp that I just created

1
  • 1
    works fine for me to remove the image, but when I tried to change the Background color in "HKCU\Control Panel\Colors\Background" it does not do it. Commented Jan 7, 2010 at 11:38
4

Here is one option. Create a small Console App with a SharpDevelop. Put this code into Programs.cs. I call the app "CWP"; Change wallpaper. It takes just one parameter on command line: the file name. Tested on Windows 7 Ultimate 64-bit with .bmp -file.

 /* * Created by SharpDevelop. * Date: 21.9.2012 * Time: 16:13 */ using System; using System.Data; using System.Text; using System.Runtime.InteropServices; namespace cwp { class Program { [DllImport("user32.dll")] public static extern Int32 SystemParametersInfo( UInt32 action, UInt32 uParam, String vParam, UInt32 winIni); public static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14; public static readonly UInt32 SPIF_UPDATEINIFILE = 0x01; public static readonly UInt32 SPIF_SENDWININICHANGE = 0x02; public static void SetWallpaper(String path) { Console.WriteLine("Setting wallpaper to '" + path + "'"); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); } public static void Main(string[] args) { if (args.Length >= 1) { SetWallpaper( args[0] ); } } } } 
4

In this time, can use python, as it says changing desktop background in windows 10 via python:

By example:

import ctypes path = 'C:\Windows\Web\Wallpaper\Windows\img0.jpg' ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 3) 
2

this isn't as cool as actually spending time writing code, but there's a pretty useful system util called bginfo that embeds info into the desktop's background. it's fairly configurable with all sorts of command-line options. no, i didn't write it.

1
  • For a solid background color, this met my needs. Created a config with just the boottime and a solid color, saved it as bginfo-justboottime.bgi and then put this line in a bat file: bginfo "C:\stuff\bginfo-justboottime.bgi" /timer0 Commented May 29, 2024 at 13:37
1

The registry method doesn't work all the time especially if the picture isn't in bmp format so you can try my method. It simply open the picture you want using windows photo viewer and use a keyboard shortcut to set the picture as your desktop wallpaper.

Dim wShell set wShell = createobject("Wscript.shell") wShell.Run "cmd /c start " & Your photo path here,0,True do wscript.sleep 100 loop until wShell.appactivate("Windows Photo Viewer") = true wShell.Sendkeys ("+{F10}") WScript.Sleep 100 wShell.Sendkeys "k" wShell.Exec "taskkill /im dllhost.exe" 

This is a vbs script but you can use the same method using cmd

1

No matter I tried I couldn't reliably change wallpaper with regedit and UpdatePerUserSystemParameters (even with large loops), so I ended up using powershell, it works every time.

See https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/

Set-Wallpaper.ps1:

# use powershell.exe Set-Wallpaper.ps1 -Image "<path to image>" param ([string]$Image="") Function Set-WallPaper($Image) { <# .SYNOPSIS Applies a specified wallpaper to the current user's desktop .PARAMETER Image Provide the exact path to the image .EXAMPLE Set-WallPaper -Image "C:\Wallpaper\Default.jpg" #> Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Params { [DllImport("User32.dll",CharSet=CharSet.Unicode)] public static extern int SystemParametersInfo (Int32 uAction, Int32 uParam, String lpvParam, Int32 fuWinIni); } "@ $SPI_SETDESKWALLPAPER = 0x0014 $UpdateIniFile = 0x01 $SendChangeEvent = 0x02 $fWinIni = $UpdateIniFile -bor $SendChangeEvent $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni) } Set-WallPaper -Image $Image 
1
  • Followup, one could try calling the function like that: "rundll32.exe user32.DLL,SystemParametersInfo 20 0 C:\wallpaper.bmp 1" and it worked back then but it does nothing now. I guess microsoft fixed security bug and rundll only runs specific methods. Commented Jan 23, 2020 at 19:22
0

For Windows 7, it works even in restricted areas!! ;) Replace your image location path with

C:\Users\1509967\Desktop\hi.jpg

reg add "HKEY_CURRENT_USER\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f reg add "HKEY_CURRENT_USER\control panel\desktop" /v wallpaper /t REG_SZ /d C:\Users\1509967\Desktop\hi.jpg /f reg add "HKEY_CURRENT_USER\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters pause exit 
0

I found that running the following commands while the Settings app is open will refresh the desktop wallpaper:

RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters 1, True RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters 

Here's a PowerShell script to set the wallpaper and ensure it updates:

Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name 'WallPaper' -Value $MyImage Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name 'WallpaperStyle' -Value 2 Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name 'TileWallpaper' -Value 0 $settings = Get-Process -Name SystemSettings -ErrorAction SilentlyContinue if (-not $settings) { Start-Process "ms-settings:" Start-Sleep -Seconds 1 } RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters 1, True RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters if (-not $settings) { Start-Sleep -Seconds 1 Stop-Process -Name "SystemSettings" } 

This ensures the wallpaper is updated immediately.

1
  • 1
    Welcome to Super User! Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places. Commented May 23, 2024 at 7:14
0

bginfo is a great tool.

Here is a PowerShell script that can:

  1. Download a random picture from unsplash.com in your specified resolution.
  2. Use bginfo to set this picture as the desktop background.
# Define the target URL and the storage directory $url = "https://source.unsplash.com/featured/3840x2160/?wallpaper" $destinationFolder = "C:\Users\kamus\OneDrive\Pictures\wallpapers" # Get the current timestamp $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" # Define the save path $destinationFile = Join-Path -Path $destinationFolder -ChildPath "$timestamp.jpg" # Check if the directory exists, if not, create it if (-Not (Test-Path -Path $destinationFolder)) { New-Item -ItemType Directory -Path $destinationFolder } # Download the image and save it Invoke-WebRequest -Uri $url -OutFile $destinationFile Write-Output "Image downloaded and saved as $destinationFile" # Define the path of the static subdirectory in the current directory $staticFolder = Join-Path -Path $destinationFolder -ChildPath "static" # Check if the static directory exists, if not, create it if (-Not (Test-Path -Path $staticFolder)) { New-Item -ItemType Directory -Path $staticFolder } # Define the target file path in the static directory $staticFile = Join-Path -Path $staticFolder -ChildPath "my-unsplash-wallpaper.jpg" # Copy the downloaded image to the static directory and rename it # Because the bginfo program can only select a specific file as the desktop wallpaper. # Please ensure that this file is set as the desktop wallpaper in the bginfo configuration. Copy-Item -Path $destinationFile -Destination $staticFile -Force Write-Output "Image copied to static directory as $staticFile" # Call the bginfo.exe command $bginfoPath = "C:\Users\kamus\scoop\shims\bginfo.exe" $bginfoArgs = "/timer:0 /Silent" Start-Process -FilePath $bginfoPath -ArgumentList $bginfoArgs -NoNewWindow -Wait Write-Output "Bginfo executed with arguments: $bginfoArgs" 

You must log in to answer this question.