AHK Wallpaper Change doesn't persist

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
meteor1942
Posts: 3
Joined: 17 Dec 2023, 14:53

AHK Wallpaper Change doesn't persist

30 Dec 2023, 15:37

So I have a snippet of code that works as expected - successfully changes the wallpaper on the desktop using:

Code: Select all

	; Update system wallpaper
	SysParamInfoResult := DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, wallpath, UInt, 1)
Strange thing I've noticed on my Windows 11 desktop, is that if I switch to another virtual desktop (via task view for example) and come back to the first virtual desktop, the changed wallpaper is gone. Replaced instead by whatever I had on there before the AHK script changed it. For further context - I have 2 different virtual desktops, each of which was assigned a different wallpaper (to distinguish the desktops easily) via the Setting>Personalization>Background menu in Windows 11.

To reiterate, the script succeeds in changing the wallpaper, except that the change doesn't persist if I switch away and then back to the said virtual desktop. Any ideas how I might be able to make the change persist?
AHK Version 1.1 // Windows 11 // Nvidia drivers and Windows up-to-date
User avatar
noname
Posts: 516
Joined: 19 Nov 2013, 09:15

Re: AHK Wallpaper Change doesn't persist

31 Dec 2023, 09:08

You can try to use 0x0003 as last parameter (fWinIni), this is the script i use on win10/11 .

DllCall("SystemParametersInfo", uint, 0x0014, uint, 0x0000, str, sfile, uint, 0x0003)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa?redirectedfrom=MSDN

SPIF_SENDWININICHANGE = 2
SPIF_UPDATEINIFILE = 1


[optional] If a system parameter is being set, specifies whether the user profile is to be updated, and
if so, whether the $WM_SETTINGCHANGE message is to be broadcast. This parameter can be zero if you don't want
to update the user profile or it can be one or more of the following values:
$SPIF_UPDATEINIFILE - Writes the new setting to the user profile
$SPIF_SENDCHANGE - Broadcasts the $WM_SETTINGCHANGE message after updating the user profile

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], CoffeeChaton, peter_ahk and 151 guests