PowerShell

Setting Desktop Background Colour Using Powershell.

Hi,

Sometime i write about doing some task with Powershell and that task are just a “Registry Tweaks”, and those tweaks can be done using some other methods too.

The idea behind with these post and scripts are, that when we are writing a powershell script, that will be completely powershell based.

For example if i creating an “Windows Customization ” tool and i need to configure few settings, then that tasks should be done by Powershell Not by something else.

“Task”

My today task was to set Desktop Background to be a specific colour.  First i was searching for how to do this using powershell and after a few minutes i have find that , that can be done by tweaking a registry key.

What we want to automate.?

we want to automate the below marked option “Change Background Colour”.

23-07-2013 19-53-16

What is current background colour.?

You can see in below picture that my current desktop background in “Dark Red”.

23-07-2013 19-57-55

Now lets Change the background to the “Green”.

The RGB Code for Green Colour is : 116 164 2

The Registry Key which holds the setting of background colour is “Background” located at “Hkey_Current_User\Control Panel\Colors”

Set-ItemProperty ‘HKCU:\Control Panel\Colors’ -Name Background -Value “116 164 2 “

Now run the above in Powershell console.

23-07-2013 20-05-39

Log off from your system and login again.

and here you go 🙂  after login back, we can see that our Desktop background colour is changed to the Green one 🙂

23-07-2013 20-08-28

Now, change the background colour of every laptop in your organization to  match with your company’s logos colour.

🙂

I hope that you will find it helpful.

 

Thanks
Aman Dhally
 
 
clip_image001 clip_image002 clip_image003 clip_image005clip_image007

7 thoughts on “Setting Desktop Background Colour Using Powershell.

  1. Thanks for that; can you also explain how to make the change instant without having to log off/on again just like control panel would do it.
    I know that it involves sending some kind of message to explorer (I think!) but I’ve no idea how to do it in PowerShell (or even if it’s possible)

    1. You are welcome Steve.
      I am looking for the same, will update the post when i find it 🙂

  2. Aman – I found the (to my mind) simplest way to do this from this post:
    http://www.heckler.com.br/blog/2011/03/29/desktop-background-slideshow-in-windows-home-basic-with-powershell/

    I use this for my code:
    $signature = @’
    [DllImport(“user32.dll”)]
    public static extern uint SystemParametersInfo(
    uint uiAction,
    uint uiParam,
    string pvParam,
    uint fWinIni);
    ‘@

    $type = Add-Type -MemberDefinition $signature -Name Win32Utils -Namespace SystemParametersInfo -PassThru

    $null = $type::SystemParametersInfo(20, 0, “C:\temp\dilbert$today.bmp”, 3)

    (I have already downloaded the dilbert cartoon and converted it to bitmap previously).

  3. Sorry – I left out a step. Prior to calling the last line “$null = $type::…”, set the background color.
    Set-ItemProperty -Path ‘HKCU:\Control Panel\Colors\’ -Name Background -Value “0 66 98”

    This sets the background color, adds the Dilbert cartoon in the center and changes immediately without logging out.

    1. Unexpected token ‘set’ in expression or statement.
      At C:\Users\Paulo\Desktop\color.ps1:7 char:22
      + “$null = $type::” set <<<< the background color.
      + CategoryInfo : ParserError: (set:String) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : UnexpectedToken

Comments are closed.