Created
November 24, 2010 17:20
-
-
Save s7ephen/714023 to your computer and use it in GitHub Desktop.
How to change the desktop wallpaper from powershell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value accipiter.png |
@gabrielkryss You can put BirkhoffLee's post above in a ps1 file like so:
# Note: if scheduling this script, you may need to check
# that the powershell session is logged in as the user
$path = $args[0]
$setwallpapersrc = @"
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 $setwallpapersrc
[Wallpaper]::SetWallpaper($path)
And call it like so:
wallpaper.ps1 D:\wallpapers\wallpaper.jpg
Or you could keep your wallpaper at a specific location (e.g., $env:LOCALAPPDATA\wallpaper.png) and have your script simply set that path as the wallpaper.
Is there a way to get these awesome scripts to work for an entire DIR, instead of single file?
Cheers
$setwallpapersrc = @"
...
Thank you very much, perfectly working with powershell, amazing :o
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an updated version of this command or is the consensus in 2022 (going into 2023) for changing wallpapers from PowerShell is to never do it and just use the UI to do it? I kind of want to be able to change my wallpaper from telescope.nivm and the first step is to be able to do it in PowerShell. Can I get a feel on what the opinions on this