I have a Python script that utilizes the ctypes library to pass parameters to Window's SystemParametersInfoW()
function in order to change my Windows 10 desktop background. I'm able to successfully change the background, however the changes aren't being applied permanently. Once I shut the computer down it'll revert to my previous background on the next boot instead of the one applied from the script.
image_path = "C:\\Users\\Jay\\source\\repos\\Nasa_Background\\Nasa_Background\\bg.png"
SPI_SETDESKWALLPAPER = 0x0014
SPIF_UPDATEINIFILE = 0x0001
SPIF_SENDWININICHANGE = 0x0002
ctypes.windll.user32.SystemParametersInfoW.argtypes = [ctypes.c_uint, ctypes.c_uint, ctypes.c_void_p, ctypes.c_uint]
ctypes.windll.user32.SystemParametersInfoW.restype = ctypes.wintypes.BOOL
ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, image_path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
According to this dev blog passing SPIF_UPDATEINIFILE
should make the change permanent:
https://devblogs.microsoft.com/oldnewthing/20160721-00/?p=93925
Everything else looks correct based on the docs: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow
I've also tried this solution with no luck: How do I set the desktop background in python? (windows)
So I'm not sure what I'm missing here, it seems like it should permanently update the background but it's not.