Windows 7 has added customizing your Windows 7 logon screen background as part of the OEM skinning features … which means it’s so easy that if I come across you and you haven’t got a custom logon background, I will personally revoke your geek/tinkerer credentials.

Having said that, it seems clear that we really need to be able to do this from PowerShell ;)

I’m going to use an image called Cold Welcome which is on DeviantArt

The Cold Welcome archive has the following image resolutions in it (but their file sizes are all too large):

  • 1024×768
  • 1280×800
  • 1280×960
  • 1440×900
  • 1600×1200
  • 1680×1050
  • 1920×1200

NOTE: Windows supports the following image resolutions as login backgrounds, but the file size has to be less than 256kb:

  • 768×1280
  • 900×1440
  • 960×1280
  • 1024×1280
  • 1024×768
  • 1280×1024
  • 1280×768
  • 1280×960
  • 1360×768
  • 1440×900
  • 1600×1200
  • 1920×1200

All you have to do is put an appropriately sized file in ${Env:SystemRoot}\system32\oobe\info\backgrounds\ with a name like background${resolution}.jpg and set a registry key value. The simple version of the script looks like this:


$ErrorActionPreference = "Stop"
## You must be ELEVATED to run this because it sets HKLM
Set-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background OEMBackground 1

$destinationFolder = "${Env:SystemRoot}\system32\oobe\info\backgrounds"
## You must be ELEVATED to run this because it writes in System32
MkDir $destinationFolder -ErrorAction SilentlyContinue

## Note: this works for me because my monitor is 1440x900 (which is supported by both the source images and the allowed destination resolutions)
$resolution = $source = "1440x900"

## Download an archive file ...
Get-WebFile http://www.deviantart.com/download/134452372/Cold_Welcome_Vista_Logon_by_Cheezen.rar Backgrounds.rar |
## Extract the file that we want to use
%{ Expand-Archive $_ -Index $(
      (Read-Archive $_ |
       Where-Object { $_.Name -match "$source.jpg" }).Index) -Passthru
 } |
## Make the filesize smaller, and copy it to the destination
## You must be ELEVATED to run this because it outputs to System32\...
Compress-Bitmap "$destinationFolder\background${resolution}.jpg" -MaxFilesize 256kb
 

Incidentally, this ought to work to extract the file but it does not, so I filed a bug filed with PSCX, and rewrote it as you see above:


Expand-Archive -EntryPath *$source.jpg -Passthru

So, if we wanted to, we could make this a little more resilient by automatically detecting the right resolution size using something like this:


Add-Type -Assembly System.Windows.Forms
$Width = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
$Height = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height
$Ratio = $Width/$Height
$resolution = "{0}x{1}" -f $Width,$Height

Technically, you’d probably want to force the $resolution to end up being one of the legal login background values (whichever was closest in dimensions and ratio), but I haven’t run into that problem yet. In any case, you can then grab the resolutions of the source images from the file names, if your files are named that way …


## Assuming you have image files with the ${Height}x${Width} naming convention:
$sources = Read-Archive .\Backgrounds.rar | ?{$_.Name -like "*.jpg" } | % { $_.Name -replace '.*[^\d](\d+x\d+).jpg','' }
if($sources -contains $resolution) {
   $source = $resolution
} else {
   ### try for one that matches the $ratio and is BIGGER
   foreach($source in $sources) {
      [int]$x,[int]$y = $source -split "x"
      $r = $x/$y
      if($r -eq $ratio -and $x -ge $Width) { break; }
   }
}

Or, you could just read in each image with Import-Bitmap (from PSCX), and test their .Width and .Height properties in a similar fashion …

Required Modules and functions

  • PSCX – The PowerShell Community Extensions.

4 Responses to “Customize your Windows 7 Logon Screen”

  • Just in case someone doesn’t read all the way through you should to change “All you have to do is put an appropriately sized file in ${Env:SystemRoot}\system32\oobe\info\background\” to “...${Env:SystemRoot}\system32\oobe\info\backgrounds\”

    Otherwise very nice and easy.

  • Does this still work for you? It was working for awhile but now it doesn’t and nothing has changed. The registry is still set and my graphic file is still in place and hasn’t been changed. The only thing I can think of is that a Windows update hosed something.