44 lines
1.5 KiB
Batchfile
44 lines
1.5 KiB
Batchfile
# 2>NUL & @CLS & PUSHD "%~dp0" & "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -noProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0')|iex" & POPD & EXIT /B
|
|
|
|
# URL of the image
|
|
$imageUrl = "https://git.hibbit.net/HHO/Powershell/raw/commit/b23adb18f027f6e1d2e900e5563c79c07fe3567a/background/vincent-van-zalinge-v_IzolP4hGA-unsplash.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 -TimeoutSec 60
|
|
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
|
|
}
|