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

total_annihilation00

  • Power Member
  • ****
  • Posts: 185
  • 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 for Custom Context Menu Integration. This script enhances the context menu to reliably set an image as wallpaper in "Stretched" mode, circumventing limitations in MC (MultiCommander) where the "Set As Background Image" option is unavailable—particularly in Flat View. By adding this as a custom context menu item (configured via Config > "Custom Context Menu"), users can consistently apply wallpapers regardless of MC's view mode.

Implementation Details:
Update the $ScriptFilePath variable in the script with your local path (ensure directory separators are escaped with double backslashes \\).
Supports multiple display modes; create five different scripts /w provided values (see below), e.g.:
    +------------------------------------------+
    | SetWallpaperMCStretched.ps1              |
    +------------------------------------------+
    | SetWallpaperMCFill.ps1                   |
    +------------------------------------------+
    | SetWallpaperMCFit.ps1                    |
    +------------------------------------------+
    | SetWallpaperMCCenter.ps1                 |
    +------------------------------------------+
    | SetWallpaperMCSpan.ps1                   |
    +------------------------------------------+
    | SetWallpaperMCTile.ps1                   |
    +------------------------------------------+

Notes:
Tested on MC 15.8 running on Windows 10.
To add to the context menu: navigate to Config > "Custom Context Menu" and add the script.

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                    |
    +--------------------------------------------------------------+
    | Span: WallpaperStyle=22, TileWallpaper=0                        |
    +--------------------------------------------------------------+
    | Tile: WallpaperStyle=0, TileWallpaper=1                        |
    +--------------------------------------------------------------+
« Last Edit: March 07, 2026, 17:21:58 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: 185
  • Tech Savant\ Envisioneering
    • View Profile
Re: [SCRIPT] Set As Background Wallpaper (Stretched etc.)
« Reply #1 on: February 14, 2026, 20:04:50 »
A significantly improved and optimized version of this script has been generated using an advanced Generative AI model, resulting in enhanced performance and efficiency. Please use the latest version provided here, while retaining the previous one for archival purposes.

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                    |
    +--------------------------------------------------------------+
    | Span: WallpaperStyle=22, TileWallpaper=0                        |
    +--------------------------------------------------------------+
    | Tile: WallpaperStyle=0, TileWallpaper=1                        |
    +--------------------------------------------------------------+

These are just quality-of-life tweaks. The core SystemParametersInfo approach remains the right one.
« Last Edit: March 07, 2026, 17:22:51 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: 185
  • Tech Savant\ Envisioneering
    • View Profile
Re: [SCRIPT] Set As Background Wallpaper (Stretched etc.)
« Reply #2 on: Today at 13:15:50 »
This is a follow-up. The previous scripts had compatibility issues with older Win 95+ OS's-based Screensavers etc. (they wouldn't detect the Wallpaper like in the BLOCKS/ Windows 98.SCR screensaver)

Legacy Windows 98 Screensaver Compatibility Fix via PowerShell
The issue stems from two primary compatibility gaps between modern Windows 10 and legacy Win32/16 architecture:

  • Image Format Limitation: Legacy screensavers (e.g., Windows 98.SCR) lack JPEG/PNG decoding capabilities and rely solely on uncompressed BMP files for textures.
  • Registry Synchronization: Modern Windows 10 manages wallpaper transcoding internally, often failing to update legacy registry keys (HKCU:\Control Panel\Desktop\Wallpaper) with raw image paths, causing detection failures.

Solution Overview:
  • On-the-fly BMP Conversion: The script leverages .NET's System.Drawing to transcode any user-selected image (JPG, PNG, WebP) into a 24-bit BMP, ensuring compatibility.
  • Reliable Storage Path: Saves the BMP to a predictable, short path (e.g., $env:USERPROFILE\classic_wallpaper.bmp) to facilitate detection by legacy screensavers.
  • Registry & API Updates: Manually updates the Wallpaper registry key with the BMP path and invokes SystemParametersInfo API with SPI_SETDESKWALLPAPER to immediately apply, ensuring the screensaver detects the correct wallpaper image.

You need five of these scripts for each of the modes (replace the code lines of each according to the following):
+--------------------------------------------------------+
|                Style Reference Map                     |
+------------------------------+-------------------------+
| Style                        | Registry Settings      |
+------------------------------+-------------------------+
| Stretch                      | WallpaperStyle='2'      |
|                              | TileWallpaper='0'       |
+------------------------------+-------------------------+
| Fit                          | WallpaperStyle='6'      |
|                              | TileWallpaper='0'       |
+------------------------------+-------------------------+
| Fill                         | WallpaperStyle='10'     |
|                              | TileWallpaper='0'       |
+------------------------------+-------------------------+
| Center                       | WallpaperStyle='0'      |
|                              | TileWallpaper='0'       |
+------------------------------+-------------------------+
| Tile                         | WallpaperStyle='0'      |
|                              | TileWallpaper='1'       |
+------------------------------+-------------------------+
| Span                         | WallpaperStyle='22'     |
|                              | TileWallpaper='0'       |
+------------------------------+-------------------------+

Here's the full script for 'Stretched', change the two values for the rest of the scripts modes:
Code: [Select]
```SetWallpaperMCStretch.ps1
param([string]$ImagePath)

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

# Load .NET Assembly for Image Processing
Add-Type -AssemblyName System.Drawing

# Define a clean, static path for the legacy BMP file
# Legacy screensavers handle paths without spaces much better
$BmpPath = "$env:USERPROFILE\classic_wallpaper.bmp"

# Convert the source image to a 24-bit BMP to satisfy the Win98 screensaver engine
try {
    $SrcImage = [System.Drawing.Image]::FromFile($ImagePath)
   
    # If a previous wallpaper BMP exists, delete it first to release file locks
    if (Test-Path $BmpPath) {
        Remove-Item $BmpPath -Force -ErrorAction SilentlyContinue
    }
   
    # Save as BMP format
    $SrcImage.Save($BmpPath, [System.Drawing.Imaging.ImageFormat]::Bmp)
    $SrcImage.Dispose()
}
catch {
    Write-Error "Failed to process and convert image: $_"
    exit 1
}

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

# FORCE legacy wallpaper path update in the registry for the screensaver
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name Wallpaper -Value $BmpPath

# 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, $BmpPath, 3)
```


Plus interface it in MC like this:
Code: [Select]
```MultiScript
@var $imgPath = GetSourceFocusPath();
@var $arguments = "-ExecutionPolicy Bypass -File \"C:\\Users\\dell\\Downloads\\thumbstick\\CUT\\SEND TO USB (COPY PDF FOLDER)\\Temp FlashDrive Store\\SendTo\\Latest Software Delete (Temp)\\SetWallpaperMCStretch.ps1\" -ImagePath \"" + $imgPath + "\"";
MC.Run CMD="cmd.exe /c powershell.exe" ARG="{$arguments}";
```

Technical Highlights:
  • Uses PowerShell + .NET for image transcoding.
  • Sets appropriate registry values (WallpaperStyle and TileWallpaper) for correct display behavior.
  • Invokes Win32 API call for immediate wallpaper refresh.
  • Ensures backward compatibility for Win95/98-style screensavers expecting BMP textures and registry cues.
~The World's Deceit Has Raped My Soul, We Melt The Plastic People Down Then We Melt Their Plastic Town~