Skip to content

Instantly share code, notes, and snippets.

@mark05e
Last active January 15, 2025 02:36
Show Gist options
  • Save mark05e/12bf14eccd3b0a7b7b694c378577639c to your computer and use it in GitHub Desktop.
Save mark05e/12bf14eccd3b0a7b7b694c378577639c to your computer and use it in GitHub Desktop.
#-------------------------------------------------------------------#
# ScriptName : SetWall.ps1 #
# Description : Force a Desktop wallpaper Refresh #
# Credits : Unknown (if you know original creator, let us know) #
# #
# Date : 01 July 2020 #
# Ref : https://c-nergy.be/blog/?p=15291 #
#-------------------------------------------------------------------#
#Modify Path to the picture accordingly to reflect your infrastructure
$imgPath="C:\Temp\Wallpaper.jpg"
if (!(Test-Path $imgPath -PathType leaf))
{
Write-Host "$imgPath not found!"
Exit
}
$code = @'
using System.Runtime.InteropServices;
namespace Win32{
public class Wallpaper{
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int SystemParametersInfo (int uAction , int uParam , string lpvParam , int fuWinIni) ;
public static void SetWallpaper(string thePath){
SystemParametersInfo(20,0,thePath,3);
}
}
}
'@
add-type $code
#Apply the Change on the system
[Win32.Wallpaper]::SetWallpaper($imgPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment