Skip to content

Instantly share code, notes, and snippets.

@ams0
Created June 10, 2025 21:07
Show Gist options
  • Save ams0/316840dfa120d623de206d203ead535d to your computer and use it in GitHub Desktop.
Save ams0/316840dfa120d623de206d203ead535d to your computer and use it in GitHub Desktop.
set background in windows 11
# Define the path to the new wallpaper
$wallpaperPath = "C:\custom-background.jpg"
# Load user32.dll and define the SystemParametersInfo function
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class User32 {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
}
"@
# Set the wallpaper
$SPI_SETDESKWALLPAPER = 0x0014
$SPIF_UPDATEINIFILE = 0x01
$SPIF_SENDCHANGE = 0x02
$flags = $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE
[User32]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $wallpaperPath, $flags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment