A PowerShell script that sets a random desktop wallpaper from a folder. It supports a Windows system tray icon with a right‑click menu to manually change the wallpaper, configure the schedule (minutes), choose the image folder, toggle subfolder inclusion, pick style, and enable/disable scheduling. Settings persist under your profile.
- System tray app (Windows Forms)
- Change now
- Set folder… (browse)
- Set interval (minutes)…
- Include subfolders (toggle)
- Style: Fill, Fit, Stretch, Center, Tile, Span
- Scheduling enabled (toggle)
- Start at logon (toggle via Startup shortcut)
- Open images folder
- Exit
- Custom tray icon
- Uses
tray.ico(oricon.ico) if present next to the script - If none is present, the script auto-generates a multi-resolution
tray.ico(16, 24, 32, 48, 64, 128, 256) with an image‑themed design (mountain + sun) - The tray and Startup shortcut will use the appropriate size for your DPI
- Uses
- One‑off or continuous (non‑tray) modes
- Optional Scheduled Task to run continuously at user logon
- Supported images:
jpg,jpeg,png,bmp
- Windows 10/11
- PowerShell 7+ (tested with 7.5.3), executable
pwsh - .NET Windows Desktop assemblies (System.Windows.Forms/System.Drawing) – present by default on Windows desktops
rand_wallpaper.ps1– the main scripttray.ico– auto-generated on first run if missing; place your own to override (or useicon.ico)- Config:
%AppData%\RandomWallpaper\config.json(created/updated by tray mode)
Run the tray app (recommended):
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -TrayThen right‑click the tray icon to configure your folder, schedule, recurse, and style. Double‑click the tray icon or select “Change now” to immediately set a random wallpaper.
Install a Startup shortcut that launches the tray app at logon:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -InstallStartupRemove it:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -UninstallStartupYou can also toggle “Start at logon” directly from the tray menu.
Notes:
- The shortcut is created in your user Startup folder with target
pwsh.exeand arguments-NoProfile -ExecutionPolicy Bypass -File "<script>" -Tray. - The shortcut icon uses
tray.icooricon.icoif available; otherwise a system icon.
Create a Scheduled Task to start the script at logon and run continuously (the script itself loops on your selected interval):
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -InstallBackground -ImageFolder "C:\Wallpapers" -IntervalMinutes 30 -Style Fill -Recurse -TaskName RandomWallpaperRemove the task:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -UninstallBackground -TaskName RandomWallpaperNotes:
- Uninstall may prompt for elevation.
- The task is registered for the current user (Interactive, Limited).
Set one random wallpaper and exit:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -OnceRun in the foreground continuously, changing every N minutes:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -ImageFolder "C:\Wallpapers" -IntervalMinutes 30 -Style Fill -RecursePress Ctrl+C to stop.
-ImageFolder <path>- Folder containing images. Default prefers
%USERPROFILE%\Pictures\Wallpapers(or Known Folders variant), otherwise falls back to%USERPROFILE%\Picturesand%USERPROFILE%\wallpapers.
- Folder containing images. Default prefers
-IntervalMinutes <int>- Minutes between changes. Default:
240. Minimum enforced:1.
- Minutes between changes. Default:
-Style <Fill|Fit|Stretch|Center|Tile|Span>- Wallpaper style. Default:
Stretch.
- Wallpaper style. Default:
-Recurse(switch)- Include images from subfolders. Default:
trueunless explicitly set otherwise.
- Include images from subfolders. Default:
-Once(switch)- Set a random wallpaper once and exit.
-Tray(switch)- Start the tray app (Windows Forms message loop). The tray has its own scheduler/timer and persists settings.
-InstallStartup/-UninstallStartup(switch)- Install/remove a Startup shortcut that launches tray mode at sign‑in.
-InstallBackground/-UninstallBackground(switch)- Install/remove a Scheduled Task that starts the script at logon and runs continuously.
-TaskName <string>- Name for the Scheduled Task. Default:
RandomWallpaper.
- Name for the Scheduled Task. Default:
- Persisted settings:
%AppData%\RandomWallpaper\config.jsonImageFolder: stringIntervalMinutes: number (minutes)Style: one ofFill|Fit|Stretch|Center|Tile|SpanRecurse: booleanScheduleEnabled: boolean (enables the tray timer)
- Timer/scheduler is internal to the tray app and can be toggled via the menu (“Scheduling enabled”).
- Double‑click the tray icon = “Change now”.
- Icon:
- Provide
tray.ico(oricon.ico) next to the script for a custom icon. A 16×16 (and/or multi‑resolution) ICO is recommended. - If not present, a small image‑style icon is drawn programmatically.
- Provide
- If you don’t see the tray icon, check the hidden icons overflow menu in the Windows taskbar.
The script sets registry values equivalent to Windows styles:
- Fill → WallpaperStyle=10, TileWallpaper=0
- Fit → WallpaperStyle=6, TileWallpaper=0
- Stretch → WallpaperStyle=2, TileWallpaper=0
- Center → WallpaperStyle=0, TileWallpaper=0
- Tile → WallpaperStyle=0, TileWallpaper=1
- Span → WallpaperStyle=22, TileWallpaper=0 (multi‑monitor spanning)
jpg,jpeg,png,bmp
- “No images found”: Check the selected folder and whether “Include subfolders” is set appropriately.
- Execution policy blocks script: use the examples here which pass
-ExecutionPolicy Bypassper‑invocation, orUnblock-File .\\rand_wallpaper.ps1as needed. - Tray icon not visible: It may be hidden in the taskbar overflow. Drag it into the visible area if desired.
- Multi‑monitor behavior: Use
Spanstyle to span a single image across displays; other styles apply per‑monitor. - OneDrive Pictures redirection: The script resolves the Windows Known Folder for Pictures to find your default
Wallpapersfolder if present. - Error “SystemParametersInfo failed…”: Ensure the image path is accessible and the file type is supported.
- Remove Startup shortcut:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -UninstallStartup
- Remove Scheduled Task:
pwsh -NoProfile -ExecutionPolicy Bypass -File .\rand_wallpaper.ps1 -UninstallBackground -TaskName RandomWallpaper
- Remove tray settings: delete
%AppData%\RandomWallpaper\config.json(optional). Close the tray app via its “Exit” menu.
Not specified.