Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Change Background Image of Windows Login Screen

0.00/5 (No votes)
5 Jun 2013 2  
A small tool I made to easily change the background image of the login screen.

Introduction

I wrote this tip as I like to change the background image of my login screen and I did not want to manually scale down and copy and paste the image every time. It also shows a nice application of the Image Resizer tool I posted before (see ImageResizer).

Scaling the Image

Since Windows only accepts .jpg images with a size below 256 KB as login background, we have to scale bigger images down before we can use them. The ImageResizer class described in ImageResizer will take care of that, so I won't go into more details about the scaling process.

The WinForms Application

602663/LoginScreenChanger.PNG

This is an extremely simple WinForms application. As you can see, there are only two buttons, one for choosing and updating the login screen background image and one for just closing the app. Depending on the size of the chosen image, it will either be copied to the correct location directly or it will be scaled down first. To illustrate this process, take a look at the code of the Form.cs file:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void FD_Open_File_FileOk_1(object sender, CancelEventArgs e)
    {
        const int MAXSIZE = 240 * 1024;
        FileInfo fi = new FileInfo(FD_Open_File.FileName);

        if (fi.Extension != ".jpg")
        {
            MessageBox.Show("ERROR: Please choose an .jpg file!");
            return;
        }

        if (fi.Length > MAXSIZE)
        {
            ImageResizer resizer = new ImageResizer(MAXSIZE, fi.FullName,
            @"C:\Windows\System32\oobe\info\backgrounds\backgrounddefault.jpg");
            resizer.ScaleImage();
        }
        else
        {
            fi.CopyTo(@"C:\Windows\System32\oobe\info\backgrounds\backgrounddefault.jpg",
                      true);
        }
        MessageBox.Show("Login screen changed successfully!");
    }

    private void B_Confirm_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void B_ChoseeImage_Click(object sender, EventArgs e)
    {
        FD_Open_File.ShowDialog();
    }
}

As you can see, the code is really straightforward. After clicking on the Choose Image button, we open a file dialog where the user can choose an image. If it is not a .jpg file, the user gets back to the application without a change. Otherwise, we check if the length of the file is bigger than the allowed file size. I have chosen a maximum size of 240 KB even though Windows allows a file size of up to 256 KB to be used as login screen background image because for some reason Windows did not display some images close to this border. Also scaling the pictures down about 16 KB more won't make a huge difference in quality in most cases. For the scaling process itself, I used the ImageResizer class which is included in the project and can also be found here: ImageResizer. If finally, everything is alright, the image is copied to the correct location on the disk, overwriting the old login screen background image. From now on, Windows will automatically use the chosen image as the login background.

Note: You should start the application as an administrator, otherwise you might not have write-access to the necessary location.

Summary

That's it! I hope you find this simple application useful and can make use of it. Any comments, suggestions, and tips are appreciated!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here