Frage

I found following command to set the Desktop Wallpaper of Windows using Python:

ctypes.windll.user32.SystemParametersInfoA(0x14, 0, 'C:\somepic.jpg', 0)

Unfortunately the Wallpaper isn't changed as I expected.

Am I missing something? Or is there another way to (permanently) change the Windows Wallpaper?

Thanks.

Edit:

Found this solution:

cmd = "REG ADD \"HKCU\Control Panel\Desktop\" /v Wallpaper /t REG_SZ /d D:\30-10-2013.jpg" #changes the Registry Key "Wallpaper"
subprocess.call(cmd) 
subprocess.call("rundll32.exe user32.dll, UpdatePerUserSystemParameters") #To update the Wallpaper

Problem: By checking the Registry entry you see, that Python messes something up with the encoding, because it removes the \30 and replaces it with a little box (like [] ).

(It works by inserting these commands in a the Windows run-dialoge.)

How to solve this encoding problem?

War es hilfreich?

Lösung

First let me say that I was not able to test if setting the Wallpaper was possible, since I do not use Windows myself.

As you can see here \30 is an escaped sequence with octal value resolving to \x18 and therefore the none printable cancel character. Be sure to escape backslashes like \\ anytime when used in strings.

For the first part of the question try using the Unicode version of the function so that ctypes passes the right data type since in Python 3 the String type changed.

ctypes.windll.user32.SystemParametersInfoW(0x14, 0, 'C:\\somepic.jpg', 0)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top