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.
This Python script:
- Connects to the Windows IDesktopWallpaper COM interface.
- Asks Windows for the ID (device path) of the first monitor.
- Uses that monitor ID to get the current wallpaper’s file path.
- Prints that path to the console.
In short: Run the script → it prints the full path to your current desktop wallpaper.
-
COM interface definition
The script defines an
IDesktopWallpaperclass that represents the Windows desktop wallpaper interface. This is done using thecomtypeslibrary, which lets Python talk to COM objects. -
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.
-
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 to1,2, etc., to target other screens. -
Getting the wallpaper path
wppath = dw.GetWallpaper(monitorid) print(wppath)
This calls
GetWallpaperwith 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. -
Cleaning up
dw.Release()
Finally, the COM object is released to free resources.
To run this script, you need:
-
Windows (because it uses a Windows-only COM interface)
-
Python installed
-
The comtypes library:
pip install comtypes
-
Save the script as something like
get_wallpaper.py. -
Open Command Prompt or PowerShell.
-
Run:
python get_wallpaper.py
-
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.