Skip to content

Instantly share code, notes, and snippets.

@aont
Last active November 15, 2025 02:26
Show Gist options
  • Select an option

  • Save aont/75d857aeb10dc23675a198e52c0af70a to your computer and use it in GitHub Desktop.

Select an option

Save aont/75d857aeb10dc23675a198e52c0af70a to your computer and use it in GitHub Desktop.

Getting the Current Wallpaper Path on Windows

If you’ve ever wanted to know exactly which image file is being used as your Windows desktop wallpaper, you might have noticed there’s no obvious option in the normal settings. However, with a bit of Python and the Windows Desktop Wallpaper API, you can get the full path to the current wallpaper image.

The script above does exactly that.


What This Script Does

This Python script:

  1. Connects to the Windows IDesktopWallpaper COM interface.
  2. Asks Windows for the ID (device path) of the first monitor.
  3. Uses that monitor ID to get the current wallpaper’s file path.
  4. Prints that path to the console.

In short: Run the script → it prints the full path to your current desktop wallpaper.


Key Parts of the Script

  1. COM interface definition

    The script defines an IDesktopWallpaper class that represents the Windows desktop wallpaper interface. This is done using the comtypes library, which lets Python talk to COM objects.

  2. Creating the COM object

    dw = comtypes.client.CreateObject(CLSID_DesktopWallpaper, interface=IDesktopWallpaper)

    This line creates an instance of the Desktop Wallpaper manager provided by Windows.

  3. Getting the monitor ID

    monitorid = dw.GetMonitorDevicePathAt(0)

    Here, the script asks for the device path of the first monitor (index 0). On multi-monitor setups, you could change the index to 1, 2, etc., to target other screens.

  4. Getting the wallpaper path

    wppath = dw.GetWallpaper(monitorid)
    print(wppath)

    This calls GetWallpaper with the monitor ID and prints the returned file path. That path is the location of the image currently used as the wallpaper for that monitor.

  5. Cleaning up

    dw.Release()

    Finally, the COM object is released to free resources.


Requirements

To run this script, you need:

  • Windows (because it uses a Windows-only COM interface)

  • Python installed

  • The comtypes library:

    pip install comtypes

How to Use It

  1. Save the script as something like get_wallpaper.py.

  2. Open Command Prompt or PowerShell.

  3. Run:

    python get_wallpaper.py
  4. You’ll see the full file path to your current wallpaper printed on the screen.


This is a handy little tool if you often change wallpapers, use wallpaper managers, or just want to know where Windows is loading that background image from.

import comtypes
import comtypes.client
import ctypes
import ctypes.wintypes
class IDesktopWallpaper(comtypes.IUnknown):
_iid_ = comtypes.GUID('{B92B56A9-8b55-4e14-9a89-0199bbb6f93b}')
_methods_ = (
comtypes.COMMETHOD([], comtypes.HRESULT, 'SetWallpaper',
(['in', 'unique'], ctypes.wintypes.LPCWSTR, "monitorID"),
(['in'], ctypes.wintypes.LPWSTR, "wallpaper"),
),
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetWallpaper',
(['in', 'unique'], ctypes.wintypes.LPCWSTR, "monitorID"),
(['out', 'string'], ctypes.POINTER(ctypes.wintypes.LPWSTR), "wallpaper"),
),
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetMonitorDevicePathAt',
(['in'], ctypes.wintypes.UINT, "monitorIndex"),
(['out', 'string'], ctypes.POINTER(ctypes.wintypes.LPWSTR), "monitorID"),
),
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetMonitorDevicePathCount', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetMonitorRECT', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'SetBackgroundColor', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetBackgroundColor', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'SetPosition', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetPosition', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'SetSlideshow', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetSlideshow', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'SetSlideshowOptions', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetSlideshowOptions', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'AdvanceSlideshow', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'GetStatus', ), # todo
comtypes.COMMETHOD([], comtypes.HRESULT, 'Enable', ), # todo
)
CLSID_DesktopWallpaper = comtypes.GUID("{C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD}")
dw = comtypes.client.CreateObject(CLSID_DesktopWallpaper, interface=IDesktopWallpaper)
monitorid = dw.GetMonitorDevicePathAt(0)
wppath = dw.GetWallpaper(monitorid)
print(wppath)
dw.Release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment