Skip to content

Instantly share code, notes, and snippets.

@atao
Created July 7, 2017 12:34
Show Gist options
  • Save atao/c0e45628081c837cab7a52adf01ce9d6 to your computer and use it in GitHub Desktop.
Save atao/c0e45628081c837cab7a52adf01ce9d6 to your computer and use it in GitHub Desktop.
Change wallpaper
# http://www.ghislain-lerda.com/2016/10/07/change-wallpaper/
$wallpaperPath = "mon_image.png"
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
{
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
}
}
"@
Add-Type -TypeDefinition $setwallpapersource
[wallpaper]::SetWallpaper($wallpaperPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment