1

I have had a look at this StackOverflow article and the same thing applies to me. Why is it that RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters 1, True does not work everytime? Is there some other way to make it work rather than repeating that until it works or is there some way to code it so that it works? .cmd , .bat and .ps1 is fine) Or is the best/only way to run it alot of times so that it works

Right now my solution is to just run that multiple time until it works. Is there any other way to refresh the desktop wallpaper without running RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters 1, True alot of times?

Roxiun
  • 185
  • 2
  • 10

1 Answers1

2

From Help https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-systemparametersinfow

Although this is from the 2001 documentation and has been removed from current.

Setting pvParam to "" removes the wallpaper. Setting pvParam to VBNULL reverts to the default wallpaper.


REM ChangeWallpaper.bat
REM Compiles ChangeWallpaper.vb to ChangeWallpaper.exe
C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\ChangeWallpaper.vb" /out:"%~dp0\ChangeWallpaper.exe" /target:winexe
pause

;ChangeWallpaper.vb
Imports System.Runtime.InteropServices

Public Module ChangeWallpaper
    Public Declare Unicode Function SystemParametersInfoW Lib "user32" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer
    Public Const SPI_SETDESKWALLPAPER = 20
    Public Const SPIF_SENDWININICHANGE = &H2
    Public Const SPIF_UPDATEINIFILE = &H1

Public Sub Main()    
    Dim Ret as Integer
    Dim FName As String
    Fname = "C:\Windows\Web\Wallpaper\Theme1\img1.jpg"
    'This below line which is commented out takes a filename on the command line
    'FName = Replace(Command(), """", "")

    Ret = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, FName, SPIF_SENDWININICHANGE + SPIF_UPDATEINIFILE)
    If Ret = 0 Then Msgbox(err.lastdllerror)
End Sub

End Module

The code is from here https://winsourcecode.blogspot.com/2019/06/changewallpaper.html

Update

This is the problem with using it

     Declare Function UpdatePerUserSystemParameters Lib "User32.dll" (ByVal i As Long, ByVal b As Boolean) As long

As you can see from the article Rundll32 is passing a hwnd (probably 0 to say Desktop is the parent) for j and RunDll32's HInst as a Boolean for b, and as this will be non zero it will be treated as true.

Noodles
  • 264
  • 2
  • 3