How to replace the Desktop background image with a solid color, using PowerShell and registry?
Indeed I found two methods. One using CMD-R
to run some windows magic, and another by setting the PATH value to null with (''
).
However, apparently there is another registry item containing the path in hex encoded form, in HKCU:\Control Panel\Desktop\TranscodedImageCache
, that you can see by the rudimentary hex conversion.
# Set the wallpaper PATH to ''
$key = 'HKCU:\Control Panel\Desktop'
Set-ItemProperty -Path $key -Name 'WallPaper' -Value ''
# Re-start windows Explorer:
Stop-Process -ProcessName explorer
# Using `CMD+R` and run :
shell:::{ED834ED6-4B5A-4bfe-8F11-A626DCB6A921} -Microsoft.Personalization\pageWallpaper
# Getting the "Transcoded" PATH:
$TIC=(Get-ItemProperty 'HKCU:\Control Panel\Desktop' TranscodedImageCache -ErrorAction Stop).TranscodedImageCache
[System.Text.Encoding]::Unicode.GetString($TIC) -replace '(.+)([A-Z]:[0-9a-zA-Z\\])+','$2'
#C:\Windows\Web\Wallpaper\Windows\_img0.jpg
Also related to this answer.
- You need to restart windows
explorer.exe
(use Sysinternal's Process Explorer or PS with:Stop-Process -ProcessName explorer
) in order for registry changes to take effect.
UPDATE: 2020-01-09
- You don't need to re-start explorer, nor compile anything via PoweShell, ... almost. From THIS blog and this SESU answer, I found a fantastic one-liner:
add-type -typedefinition "using System;`n using System.Runtime.InteropServices;`n public class PInvoke { [DllImport(`"user32.dll`")] public static extern bool SetSysColors(int cElements, int[] lpaElements, int[] lpaRgbValues); }"
# Now to get your desktop to instantly turn purple, run it with:
[PInvoke]::SetSysColors(1, @(1), @(0xAA40C0))
# Or tack it on the end of above for a true one-line experience.
Notes from author: "This doesn't affect the Registry, so if you want the change to stick, you need to also write the new data to Registry yourself."