Click here to Skip to main content
15,040,212 members
Articles / Programming Languages / C#
Tip/Trick
Posted 4 Jun 2013

Tagged as

Stats

18.7K views
474 downloads
14 bookmarked

Change Background Image of Windows Login Screen

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
5 Jun 2013CPOL2 min read
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Philipp_Engelmann
Software Developer (Senior)
Germany Germany
Hi there 🙂
My name is Philipp Engelmann, I work as a web developer at FIO SYSTEMS AG in Leipzig. I am interested in C#, Python, (REST-)API-Design, software architecture, algorithms and AI. Check out my blog at https://cheesyprogrammer.com/

Comments and Discussions

 
Questionno demo file found Pin
Member 139385505-Aug-18 7:48
MemberMember 139385505-Aug-18 7:48 
Questionwindow 10 ; cannot find directory / path Pin
Member 1244630124-Jul-16 21:51
MemberMember 1244630124-Jul-16 21:51 
AnswerRe: window 10 ; cannot find directory / path Pin
Philipp_Engelmann22-Dec-17 1:51
MemberPhilipp_Engelmann22-Dec-17 1:51 
I think with Windows 10, the paths are very different to Windows 7, so you will have to come up with a different solution. Maybe finding the right path already helps.
QuestionJpeg Files Pin
charles henington18-Jun-13 14:58
Membercharles henington18-Jun-13 14:58 
AnswerRe: Jpeg Files Pin
Philipp Engelmann19-Jun-13 5:24
MemberPhilipp Engelmann19-Jun-13 5:24 
GeneralRe: Jpeg Files Pin
charles henington20-Jun-13 0:27
Membercharles henington20-Jun-13 0:27 
GeneralRe: Jpeg Files Pin
Philipp Engelmann20-Jun-13 1:03
MemberPhilipp Engelmann20-Jun-13 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.