[CmdletBinding()] param( [string]$Path, [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')] [string]$Style = 'Fill', [switch]$Apply ) $ErrorActionPreference = 'Stop' $current = (Get-ItemProperty -LiteralPath 'HKCU:\Control Panel\Desktop' -Name Wallpaper -ErrorAction SilentlyContinue).Wallpaper if ($current) { Write-Host "Текущие обои: $current" } else { Write-Host 'Текущие обои не заданы.' } if (-not $Path) { Write-Host 'Укажите -Path с изображением JPG, PNG или BMP.' return } $resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path if (-not (Test-Path -LiteralPath $resolved -PathType Leaf)) { throw "Файл не найден: $resolved" } $extension = [IO.Path]::GetExtension($resolved).ToLowerInvariant() if ($extension -notin @('.jpg', '.jpeg', '.png', '.bmp')) { throw "Неподдерживаемый формат: $extension. Нужен JPG, PNG или BMP." } if (-not $Apply) { Write-Host "Будет установлено: $resolved" Write-Host "Режим: $Style. Для применения добавьте -Apply." return } $styles = @{ Fill = @(10, 0) Fit = @(6, 0) Stretch = @(2, 0) Tile = @(0, 1) Center = @(0, 0) Span = @(22, 0) } $pair = $styles[$Style] Set-ItemProperty -LiteralPath 'HKCU:\Control Panel\Desktop' -Name WallpaperStyle -Value $pair[0] Set-ItemProperty -LiteralPath 'HKCU:\Control Panel\Desktop' -Name TileWallpaper -Value $pair[1] if (-not ('WallpaperApi' -as [type])) { Add-Type @" using System; using System.Runtime.InteropServices; public class WallpaperApi { [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); } "@ } $result = [WallpaperApi]::SystemParametersInfo(20, 0, $resolved, 3) if ($result -eq 0) { throw 'SystemParametersInfo не смогла установить обои.' } Write-Host "Обои установлены: $resolved" Write-Host "Режим: $Style"