Skip to content

Instantly share code, notes, and snippets.

@ByteDev
Last active May 11, 2021 03:52
Show Gist options
  • Save ByteDev/8ab1ace769038d5f6343feb6e3484983 to your computer and use it in GitHub Desktop.
Save ByteDev/8ab1ace769038d5f6343feb6e3484983 to your computer and use it in GitHub Desktop.
Set a certain image to windows desktop wallpaper on system startup

Set WallPaper

Set a certain image to windows desktop wallpaper on system startup.

1. set-wallpaper.bat

Create set-wallpaper.bat:

@echo off
Powershell.exe -executionpolicy remotesigned -File set-wallpaper.ps1

2. set-wallpaper.ps1

Create in same directory set-wallpaper.ps1:

Function Set-WallPaper($imagePath) 
{
 
Add-Type -TypeDefinition @" 
using System; 
using System.Runtime.InteropServices;
 
public class Params
{ 
    [DllImport("User32.dll",CharSet=CharSet.Unicode)] 
    public static extern int SystemParametersInfo (Int32 uAction, 
                                                   Int32 uParam, 
                                                   String lpvParam, 
                                                   Int32 fuWinIni);
}
"@ 
 
	$SPI_SETDESKWALLPAPER = 0x0014
	$UpdateIniFile = 0x01
	$SendChangeEvent = 0x02
	 
	$fWinIni = $UpdateIniFile -bor $SendChangeEvent
	 
	$ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $imagePath, $fWinIni)
}

Set-WallPaper -imagePath "C:\Files\Images\3840x1600\Pluto.jpg"

3. Run batch file on startup

Set set-wallpaper.bat to run on startup:

Task Manager -> Start-up

Or: Run (WINDOWS + R) and type shell:startup, paste .bat/shortcut file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment