As of my last update in April 2023, there isn’t a direct, built-in command line tool in Windows 10 specifically designed to replicate the "Next desktop background" action seen in the context menu for rotating through backgrounds. However, you can accomplish this through a variety of scripting methods or third-party tools. Here's one approach using PowerShell, which doesn't exactly mimic the "Next desktop background" command (since that command is part of the shell and doesn't have a direct PowerShell equivalent) but achieves a similar result by setting the desktop background to a random image from a specified folder.
PowerShell Script to Change Desktop Background Randomly
powershell
# Specify the path where your wallpapers are stored
$wallpapersPath = "C:\Path\To\Your\Wallpapers"
# Get a random image from the wallpapers directory
$imagePath = Get-ChildItem -Path $wallpapersPath -Filter *.jpg | Get-Random -Count 1
# Use SystemParametersInfo to set the desktop background
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);
}
"@
# Define SPI_SETDESKWALLPAPER action
$SPI_SETDESKWALLPAPER = 0x0014
# Make the change persistent across reboots
$SPIF_UPDATEINIFILE = 0x01
$SPIF_SENDCHANGE = 0x02
# Apply the wallpaper
$result = [Wallpaper]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $imagePath.FullName, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
if ($result -ne 0) {
Write-Output "Wallpaper set to $($imagePath.FullName)"
} else {
Write-Error "Failed to set wallpaper."
}
Ensure you change the $wallpapersPath variable to the folder where your wallpapers are stored, and the script currently filters for .jpg images, so adjust the -Filter *.jpg part if your wallpapers have a different format.
This script does not directly invoke the "Next desktop background" feature but rather randomly selects an image from a specified folder and sets it as the desktop background, somewhat replicating the intended functionality.
To run this script:
Open PowerShell—ideally as administrator.
You may need to adjust the execution policy to allow scripts to run. Use Set-ExecutionPolicy RemoteSigned or a policy level that suits your security model.
Save the script to a .ps1 file and execute it, or paste the code directly into your PowerShell console.
Remember, directly manipulating system parameters and script execution policies carries risks; be aware of these and ensure you have adequate backups and permissions.