Reputation: 5989
I want to refresh wallpaper in Windows 7 from command line.
I'm setting wallpaper via reg.exe add
.
rundll32.exe user32.dll,UpdatePerUserSystemParameters
doesn't work (with 1,True
or 1,False
)
Requirements:
Upvotes: 2
Views: 9866
Reputation: 33381
I'm on Windows 11, the RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
will work, but only if there is some time between the edit of the registry and the execution of the command.
The following PowerShell snippet will do an instant reload:
try {
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Wallpaper {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(uint uiAction, uint uiParam, string pvParam, uint fWinIni);
}
"@
}
catch {
# only on the first time the script runs
# the type can be added
}
$SPI_SETDESKWALLPAPER = 0x0014
$SPIF_UPDATEINIFILE = 0x01
$SPIF_SENDCHANGE = 0x02
$Result = [Wallpaper]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $null, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
My use case might be different, as I needed to change my wallpaper trough the registery: How to bypass company wallpaper as local admin on Windows 11.
Upvotes: 0
Reputation: 1
reg add works better using .bmp files
this requires users to execute rundll32 multiple? times
try a simple rename conversion picture.jpeg -> picture.bmp
Upvotes: 0
Reputation: 708
At least on Windows 7 64-bit, I found that the rundll32.exe command worked, but just not every time. I don't have a theory of why, but my workaround was a .cmd file that calls it a lot of times. It's not elegant but it works every time. In our environment, we are launching it in the background async and invisible, so the fact that it runs for about 80 seconds just doesn't matter.
:: Do your stuff to apply the background .reg settings first
:: Then run UpdatePerUserSystemParameters many times
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
timeout 1
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
timeout 1
:: Etc. I have about 80 of them
Upvotes: 1
Reputation: 11
Killing explorer is never a good idea, try this:
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
Upvotes: 1
Reputation: 3289
Harder than I thought. Depending on your other needs you could eventually restart explorer.
taskkill /IM explorer.exe /F
explorer.exe
If you can call a program from the command line, you could also look at How to force Windows desktop background to update or refresh
Upvotes: 0