1

I would like to replace the default Desktop background image with a darker solid color, on an unregistered Windows 10 Pro (Insider Preview) edition. I am testing various terminal coloring schemes, and the default image is annoyingly too bright and not solid. I have tried all sorts of registry settings and also renaming and replacing the image, but it's always the same.

A few things I tried:

# Take (user) owbership of file:
takeown /F C:\Windows\Web\Wallpaper\Windows\img0.jpg
# C:\Windows\Web\Wallpaper\Windows\img0.jpg

$key = 'HKCU:\Control Panel\Colors'         # 
$key = 'HKCU:\Control Panel\Desktop'        # 
$key = 'HKCU:\Control Panel\Desktop\Colors' # 

# Doesn't seem to effect the Desktop...only console
Set-ItemProperty -Path $key -Name 'Window' -Value '1 36 86'
# reset to default
Set-ItemProperty -Path $key -Name 'Window' -Value '255 255 255'

How can I use PowerShell to set the correct registry item(s) to remove the background image and get a solid color?

2
  • 2
    $key = "HKCU:\Control Panel\Desktop";Set-ItemProperty -Name WallPaper -Path $key -Value ''
    – JosefZ
    Dec 20, 2018 at 15:49
  • Thanks @JosefZ I must have found the solution while you were typing.
    – not2qubit
    Dec 20, 2018 at 16:12

2 Answers 2

2

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."

2
  • 1
    Good point! In this case, you needn’t to restart explorer.exe. Right-click the desktop + Refresh should suffice
    – JosefZ
    Dec 20, 2018 at 17:26
  • 1
    Cool! Is there a powershell command to refresh desktop?
    – not2qubit
    Jan 9, 2020 at 19:43
0

I finalized the not2qubit solution by calling C#. I cleared the current wallpaper and saved the new color value to the registry

Variable $color store new color to set.

Variable $CSharpScript store C# script to call.

Base code for C# get from here: https://stackoverflow.com/questions/7309943/c-set-desktop-wallpaper-to-a-solid-color

With [SolidWallpaper]::SetWallpaper($color) we could call created C# function, where SolidWallpaper is created class and SetWallpaper is created function

$color = 0xf0f0f0

$CSharpScript = @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;

public class SolidWallpaper
{
  public const int SetDesktopWallpaper = 20;
  public const int UpdateIniFile = 0x01;
  public const int SendWinIniChange = 0x02;

  [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fWinIni);

  [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  private static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);

  public static void SetWallpaper(uint color) {
    // clear current wallpaper and update ini
    SystemParametersInfo(SetDesktopWallpaper, 0, "", UpdateIniFile | SendWinIniChange);

    // set solid color
    int[] lpaElements = { 1 };
    uint[] lpaRgbValues = { color };
    SetSysColors(1, lpaElements, lpaRgbValues);

    // save to registry
    int rgb = (int)color;
    RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true);
    key.SetValue(@"Background", string.Format("{0} {1} {2}", (rgb >> 16) & 0xff, (rgb >> 8) & 0xff, (rgb >> 0) & 0xff));
  }
}
"@

add-type -typedefinition $CSharpScript
[SolidWallpaper]::SetWallpaper($color)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .