42 lines
1.3 KiB
PowerShell
42 lines
1.3 KiB
PowerShell
# URL of the image
|
|
$imageUrl = "https://nedshare.nl/u/6W5EiCw4R.jpg"
|
|
|
|
# Create temp directory if it doesn't exist
|
|
$tempDir = "$env:TEMP\wallpaper"
|
|
if (-not (Test-Path $tempDir)) {
|
|
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
|
|
}
|
|
|
|
# Download the image
|
|
$wallpaperPath = "$tempDir\background.jpg"
|
|
Write-Host "Downloading wallpaper..." -ForegroundColor Yellow
|
|
try {
|
|
Invoke-WebRequest -Uri $imageUrl -OutFile $wallpaperPath
|
|
Write-Host "Download complete!" -ForegroundColor Green
|
|
} catch {
|
|
Write-Error "Failed to download wallpaper: $_"
|
|
exit 1
|
|
}
|
|
|
|
# Set the wallpaper
|
|
try {
|
|
$code = @'
|
|
using System.Runtime.InteropServices;
|
|
public class Wallpaper {
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
|
|
}
|
|
'@
|
|
|
|
Add-Type -TypeDefinition $code
|
|
$SPI_SETDESKWALLPAPER = 0x0014
|
|
$SPIF_UPDATEINIFILE = 0x01
|
|
$SPIF_SENDCHANGE = 0x02
|
|
|
|
[Wallpaper]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $wallpaperPath, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
|
|
Write-Host "Wallpaper set successfully!" -ForegroundColor Green
|
|
} catch {
|
|
Write-Error "Failed to set wallpaper: $_"
|
|
exit 1
|
|
}
|