Skip to content

Commit ddaea94

Browse files
Added Desktop Wallpaper PS Script
1 parent dd9dfe1 commit ddaea94

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<#
2+
.SYNOPSIS
3+
Change Desktop Wallpaper for a User on Win11
4+
5+
.DESCRIPTION
6+
Below Script will download a wallpaper from a Publicly accessible
7+
location and Update on the device for a particular user
8+
.NOTES
9+
Name : Change-Desktop-Wallpaper.ps1
10+
Author : Jatin Makhija
11+
Version : 1.0.0
12+
DateCreated: 15-Nov-2023
13+
Blog : https://cloudinfra.net
14+
15+
.LINK
16+
https://cloudinfra.net
17+
#>
18+
19+
# Specify the URL of your custom wallpaper
20+
$wallpaperUrl = 'https://cloudinfrasa01.blob.core.windows.net/wallpapers/Cloudinfra-desktop-wall.jpg'
21+
22+
# Specify the local path to the wallpaper folder and file
23+
$wallpaperFolder = "C:\Wallpaper-files"
24+
$localWallpaperPath = Join-Path $wallpaperFolder "wallpaper.jpg"
25+
26+
# Check if the folder exists, and create it if not
27+
if (-not (Test-Path $wallpaperFolder -PathType Container)) {
28+
New-Item -Path $wallpaperFolder -ItemType Directory -Force
29+
}
30+
31+
# Download the wallpaper
32+
Invoke-WebRequest -Uri $wallpaperUrl -OutFile $localWallpaperPath
33+
34+
# Check if the download was successful
35+
if (Test-Path $localWallpaperPath -PathType Leaf) {
36+
# Set the registry key for the wallpaper
37+
$registryPath = 'HKCU:\Control Panel\Desktop'
38+
$name = 'Wallpaper'
39+
Set-ItemProperty -Path $registryPath -Name $name -Value $localWallpaperPath
40+
41+
# Refresh the desktop to apply the changes
42+
$signature = @"
43+
[DllImport("user32.dll", SetLastError = true)]
44+
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
45+
"@
46+
$SPI_SETDESKWALLPAPER = 0x0014
47+
$UPDATE_INI_FILE = 0x01
48+
$SEND_CHANGE = 0x02
49+
$null = Add-Type -MemberDefinition $signature -Name WinAPI -Namespace SystemParametersInfoFunctions -PassThru
50+
[SystemParametersInfoFunctions.WinAPI]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $localWallpaperPath, $UPDATE_INI_FILE -bor $SEND_CHANGE)
51+
52+
Write-Host "Wallpaper changed successfully."
53+
} else {
54+
Write-Host "Error: Wallpaper download failed from $wallpaperUrl."
55+
}

0 commit comments

Comments
 (0)