Author Topic: [SCRIPT] Set As Background Wallpaper (Stretched etc.)  (Read 291 times)

total_annihilation00

  • Power Member
  • ****
  • Posts: 158
  • Tech Savant\ Envisioneering
    • View Profile
[SCRIPT] Set As Background Wallpaper (Stretched etc.)
« on: February 06, 2026, 03:38:16 »
Useful 'Set As Wallpaper (Stretched)' PowerShell Script I added as a 'Custom Context Menu' since MC doesn't give you the "Set As Background Image" option for instance when in a Flat View (doesn't show up), this custom command will always display though (change the Script FilePath tailored to your own path (remember directory subpaths must be in double slashes)) (To add to Context Menu goto Config > "Custom Context Menu") [Tested on MC 15.8 running Windows 10] (P.S: I made 5 PowerShell Scripts files, for each of the different modes (for instance: SetWallpaperMCStretched.ps1, SetWallpaperMCFill.ps1, SetWallpaperMCFit.ps1, SetWallpaperMCCenter.ps1, SetWallpaperMCTile.ps1)):

claude-opus-4-5-20251101-thinking-32k AI Generated::
## Step 1: Fixed PowerShell Script

Save this as `C:\SetWallpaper.ps1`:

```powershell
Code: [Select]
param([string]$ImagePath)

# Load WinForms so MessageBox works
# Add-Type -AssemblyName System.Windows.Forms

# Debug: Show what path was received (remove this line after testing)
# [System.Windows.Forms.MessageBox]::Show($ImagePath)

Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name WallpaperStyle -Value '2'
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name TileWallpaper -Value '0'

$code = @"
using System;
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 -ErrorAction SilentlyContinue
[Wallpaper]::SystemParametersInfo(20, 0, $ImagePath, 3)
```
---

## Step 2: Corrected MC.Run Command

The issue is likely the variable not expanding properly. Try this (Save this as a User-Defined Command then add it to Config > Custom Context Menu to set the selected file as a Stretched Wallpaper):

```multiscript
Code: [Select]
@var $imgPath = GetSourceFocusPath();
@var $arguments = "-ExecutionPolicy Bypass -File \"C:\\SetWallpaper.ps1\" -ImagePath \"" + $imgPath + "\"";
MC.Run CMD="powershell.exe" ARG="{$arguments}";
```
---

Notes (if you want other styles later)
These registry values are the ones Windows uses:
  • Stretch: WallpaperStyle=2, TileWallpaper=0 (used above)
  • Fill: WallpaperStyle=10, TileWallpaper=0
  • Fit: WallpaperStyle=6, TileWallpaper=0
  • Center: WallpaperStyle=0, TileWallpaper=0
  • Tile: WallpaperStyle=0, TileWallpaper=1
« Last Edit: Yesterday at 20:26:38 by total_annihilation00 »
~The World's Deceit Has Raped My Soul, We Melt The Plastic People Down Then We Melt Their Plastic Town~


total_annihilation00

  • Power Member
  • ****
  • Posts: 158
  • Tech Savant\ Envisioneering
    • View Profile
Re: [SCRIPT] Set As Background Wallpaper (Stretched etc.)
« Reply #1 on: Yesterday at 20:04:50 »
Found a better & more improved (& much faster) version of this script thanks to an updated Generative AI ! Use this instead (as old one is kept for pure posterity)…

claude-opus-4-6-thinking AI Generated:::
PowerShell Script (SetWallpaperMCStretch.ps1)
Code: [Select]
param([string]$ImagePath)

# Validate file exists
if (-not (Test-Path $ImagePath)) {
    Write-Error "File not found: $ImagePath"
    exit 1
}

# Set style: Stretch
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name WallpaperStyle -Value '2'
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name TileWallpaper -Value '0'

# Apply wallpaper via Win32 API
Add-Type -TypeDefinition @"
using System;
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);
}
"@ -ErrorAction SilentlyContinue

# SPI_SETDESKWALLPAPER = 0x0014 (20)
# SPIF_UPDATEINIFILE | SPIF_SENDCHANGE = 3
[Wallpaper]::SystemParametersInfo(20, 0, $ImagePath, 3)

<#
Style Reference:
  Stretch : WallpaperStyle=2,  TileWallpaper=0
  Fill    : WallpaperStyle=10, TileWallpaper=0
  Fit     : WallpaperStyle=6,  TileWallpaper=0
  Center  : WallpaperStyle=0,  TileWallpaper=0
  Tile    : WallpaperStyle=0,  TileWallpaper=1
  Span    : WallpaperStyle=22, TileWallpaper=0
#>

MultiScript (Custom Command)
Code: [Select]
@var $imgPath = GetSourceFocusPath();
@var $scriptPath = "C:\\Path\\To\\SetWallpaperMCStretch.ps1";
@var $arguments = "-ExecutionPolicy Bypass -WindowStyle Hidden -File \"" + $scriptPath + "\" -ImagePath \"" + $imgPath + "\"";
MC.Run CMD="powershell.exe" ARG="{$arguments}" FLAGS="NOWAIT|NOCONSOLE";

Notes (if you want other styles later)
These registry values are the ones Windows uses:
  • Stretch: WallpaperStyle=2, TileWallpaper=0 (used above)
  • Fill: WallpaperStyle=10, TileWallpaper=0
  • Fit: WallpaperStyle=6, TileWallpaper=0
  • Center: WallpaperStyle=0, TileWallpaper=0
  • Tile: WallpaperStyle=0, TileWallpaper=1

These are just quality-of-life tweaks. The core SystemParametersInfo approach remains the right one.
« Last Edit: Yesterday at 20:15:50 by total_annihilation00 »
~The World's Deceit Has Raped My Soul, We Melt The Plastic People Down Then We Melt Their Plastic Town~