-3

I have a folder containing several wallpaper packs set to shuffle as my desktop wallpaper on Windows 10. I am trying to write a Python script that will retrieve or delete the currently displayed wallpaper from its source, and so I need the location of the current wallpaper. Can anyone help me?

Edit: Desktop backgrounds are managed through the Settings app on Windows 10, so I'm thinking I can find the wallpaper if I can find the Settings app in the registry. Anyone know where that is?

1 Answers1

3

It is stored in a registry key located here:

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper

In order to view registry keys you can

  • type Win+r
  • type regedit
  • hit enter
Penguinparty
  • 126
  • 4
  • There is no Wallpaper folder under Desktop, maybe it's different for Windows 10? – shannara100 Dec 31 '15 at 21:38
  • 1
    @Bayya, the registry equivalent of a folder is a "key". The equivalent of a filename is a "value", and the value type (e.g. `REG_SZ`) plays the role of a filename extension. However, unlike file-system paths, a registry path can only contain keys, not values. You can't open a value directly. You open a key and enumerate its values. Sometimes you'll see people include the value name in a path, but that's not really a valid path. In this case the path is `HKCU\Control Panel\Desktop` and the value is `Wallpaper`. – Eryk Sun Dec 31 '15 at 22:23
  • That said, the registry location is an implementation detail. Use the API instead: `user32 = ctypes.WinDLL('user32', use_last_error=True);` `SPI_SETDESKWALLPAPER = 0x14;` `SPIF_UPDATEINIFILE = 1;` `SPIF_SENDCHANGE = 2;` `wallpaper_path = u'C:\\Absolute\\Path\\To\\Wallpaper.jpg';` `if not user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, wallpaper_path, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE): raise ctypes.WinError(ctypes.get_last_error())`. Note that the image path must be a `unicode` string. I'd like to use a [r]aw string, but Python 2 processes `\u` and `\U` in 'raw' unicode strings. – Eryk Sun Dec 31 '15 at 23:05