How do I change the setting in Settings App > Personalization > Background so that it uses one of the three selections with PowerShell. I just want it to change the Background setting only, not alter the existing settings or change the background in the background that is controlled by a script. So far I see things where people use powershell to change the background image, but not just control that one setting.
-
Please check if this can answer you: Set Windows 10 background slideshow script in Powershell– SunnyCommented Dec 17, 2020 at 3:41
-
I tried that one it just seems either set only one background and the next background option does not appear on the desktop.– Archimedes TrajanoCommented Jan 14, 2021 at 3:51
1 Answer
Navigate to %APPDATA%\Microsoft\Windows\Themes and copy slideshow.ini and store it somewhere safe, open slideshow.ini and copy the long string after
[Slideshow] ImagesRootPIDL=/copy-the-long-string-from-here/
Paste the string as SlideshowDirectoryPath1's value in the script.
Edit slideshow.ini path in the script with the one you stored earlier.
$sourceFile = "C:\slideshow.ini"
Read more at https://diymediahome.org/how-to-enable-windows-desktop-wallpaper-slideshow-silently-with-a-script/
Powershell script:
#-------------------------------------------------------------------#
# ScriptName : Slideshow.ps1 #
# Description : Enable Desktop Slideshow (tested, Windows 11 23H2) #
# Credits : Ken #
# #
# Date : 24 May 2024 #
#-------------------------------------------------------------------#
# Set registry values for desktop slideshow, 0x0000ea60 is 1 minute interval
$regPath = "HKCU:\Control Panel\Personalization\Desktop Slideshow"
Set-ItemProperty -Path $regPath -Name "Interval" -Value 0x0000ea60
Set-ItemProperty -Path $regPath -Name "Shuffle" -Value 0x00000001
# Fill long path string in "SlideshowDirectoryPath1"
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers"
Set-ItemProperty -Path $regPath -Name "SlideshowSourceDirectoriesSet" -Value 0x00000001
Set-ItemProperty -Path $regPath -Name "BackgroundType" -Value 0x00000002
Set-ItemProperty -Path $regPath -Name "SlideshowDirectoryPath1" -Value "put-long-string-here"
# Change path of your source slideshow you wish to move to Themes folder
$sourceFile = "C:\slideshow.ini"
# Themes folder path
$destinationDir = "$env:APPDATA\Microsoft\Windows\Themes"
# Create the themes directory if it doesn't exist, uncomment if needed.
#if (-not (Test-Path -Path $destinationDir)) {
# New-Item -Path $destinationDir -ItemType Directory -Force | Out-Null
#}
Copy-Item -Path $sourceFile -Destination $destinationDir -Force
# Check if the "Settings" app is running, if yes, close it, open it the second time and finally close it.
$settingsApp = Get-Process -Name "SystemSettings" -ErrorAction SilentlyContinue
if ($settingsApp) {
# Minimize the "Settings" app window
$showWindowAsync = Add-Type -MemberDefinition @"
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
"@ -Name "Win32ShowWindowAsync" -PassThru
$showWindowAsync::ShowWindow($settingsApp.MainWindowHandle, 6) | Out-Null
# Close the "Settings" app
Stop-Process -InputObject $settingsApp -Force
}
$settingsApp = Get-Process -Name "SystemSettings" -ErrorAction SilentlyContinue
$retryCount = 2
$retryDelay = 2
for ($i = 0; $i -lt $retryCount; $i++) {
try {
Start-Process -FilePath "ms-settings:personalization-background" -WindowStyle Hidden
break
}
catch [System.InvalidOperationException] {
if ($i -eq $retryCount - 1) {
throw
}
Write-Host "Failed to open the Settings app. Retrying in $retryDelay seconds..."
Start-Sleep -Seconds $retryDelay
}
}
Start-Sleep -Seconds 1
# Check if the "Settings" app is running again, comment # below lines if you wish to not close settings app.
$settingsApp = Get-Process -Name "SystemSettings" -ErrorAction SilentlyContinue
if ($settingsApp) {
Stop-Process -InputObject $settingsApp -Force
}