Click here to Skip to main content
14,304,866 members

Folderbackground Customizer

Rate this:
3.50 (4 votes)
Please Sign up or sign in to vote.
3.50 (4 votes)
29 May 2008CPOL
Select image and folder, then against the click button set the image as background at that folder.


This code sets the background at the specified folder.


Earlier, the user did not have any user interactive/friendly interface. The user could interact with the OS through DOS or any type of command prompt that then became interfaces for interacting with the OS and other applications. Then the user wanted to set different backgrounds at the desktop but user may have also wanted to set the background at many other places, for example at the background of any folder. Now, the user can fulfill his/her desire through different software.

Using the Code

Before going to the code, I want to explain the manual procedure which the code performs during execution.

Select the folder you want to use for your background wallpaper. You MUST convert the folder you want to use to a SYSTEM folder. At the command prompt screen (Start/Run/CMD) which looks something like this: c:\>, type this command: attrib +s c:\myfolder and then hit the return key.

Copy and paste the script below into Notepad and change the line that says IconArea_Image to point to the directory and the file that you want to use for the background image.



The last line in the script tells Windows what color the font will be when you read the files in that folder. For instance:

0x00000000 = black
0x00FF0000 = blue
0x0000FF00 = green
0x000000FF = red
0x00C000C0 = purple

Save the file you just created as desktop.ini and place it into the directory you just converted into a system folder.

Now close that folder and then reopen.

Let's see how the code performs the above procedure automatically:

//this code will be used for selecting the folder location        
private void folderpbtn_Click(object sender, EventArgs e)
    FolderBrowserDialog openFolder = new FolderBrowserDialog();
    //openFolder.RootFolder = System.Environment.SpecialFolder ("C:\\");
    if (openFolder.ShowDialog() == DialogResult.OK)
        if ((folderpath = openFolder.SelectedPath) != null)
            this.folderptxt.Text = folderpath;
}  //now for image selection as the background of the specified folder
private void bgibtn_Click(object sender, EventArgs e)
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.InitialDirectory = "c:\\";
    openFileDialog1.Filter = "Jpg files (*.jpg)|*.jpg|Bitmap files (*.bmp)|*.bmp|" +
                             "Icon files (*.ico)|*.ico|Jpeg files (*.jpeg)|*.jpeg|" +
                             "Exif files (*.bmp)|*.exif|TIFF files (*.tiff)|*.tiff";
    openFileDialog1.FilterIndex = 1;
    openFileDialog1.RestoreDirectory = true;
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
        if ((imagepath = openFileDialog1.FileName) != null)
            this.bgitxt.Text = imagepath;
            // Set the SizeMode property to the StretchImage value. This
            // will shrink or enlarge the image as needed to fit into
            // the PictureBox.
            this.imagepicbox.SizeMode = PictureBoxSizeMode.StretchImage;
            this.imagepicbox.Image = System.Drawing.Image.FromFile(imagepath);
}  //now for converting the selected folder into the system folder 
void run()
        path = String.Concat("\"", path);
        path = String.Concat(path, "\"");
        FileStream aFile = new FileStream("test.bat", FileMode.Create);
        StreamWriter sw = new StreamWriter(aFile);
        //Write data to the file
        sw.WriteLine(String.Concat("attrib +s ", path));
        //MessageBox.Show(String.Concat("attrib +s ", path));
        // Directory.Move(path, "C:\\hello");
    catch (IOException e)
        Console.WriteLine("An IO exception have been thrown !");

//for running the batch file which will convert the folder into the system folder and 
// batch file lies at absolute path
public void OpenApplication()

// code for final step creating desktop.ini file in the specified folder
class background
    string imagepath,folderpath;
    public background(string imageaddress,string folderaddress)
        imagepath = imageaddress;
        folderpath = folderaddress;
    public void setbackground()

    void set()
        string file=String.Concat(folderpath, "\\desktop.ini");
        if (File.Exists(file))
            if (MessageBox.Show("It may be change your Operating system setting?", 
                "User Database Application",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
    void makefile(string filepath)
            FileStream aFile = new FileStream
				(filepath, FileMode.CreateNew, FileAccess.Write);
            File.SetAttributes(filepath, FileAttributes.Hidden);
            StreamWriter sw = new StreamWriter(aFile);
            sw.WriteLine("[{BE098140-A513-11D0-A3A4-00C04FD706EC}] ");
            sw.WriteLine(String.Concat("IconArea_Image = ", imagepath));
        catch (IOException e)
            MessageBox.Show("Background can not be set on the specified folder");
        catch (Exception ex)
            MessageBox.Show("Background can not be set on the specified folder");

Now the background has been set at the specified folder.
Tip: If a folder uses the wrong background picture and you can't change it: Start/Run/Regedit and remove this key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Bags.

Points of Interest

In this code, I run the command prompt and execute a specified command (attrib: +s "folder path") which converts the folder into the system folder and also does some file handling which changes file attributes and removes the background from the specified folder by deleting the desktop.ini file from the specified folder.


  • 29th May, 2008: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Abbas Ali Butt
Pakistan Pakistan
My name is Abbas Ali Butt. I am a student of Punjab University Information and Technology.

Comments and Discussions

Question“Attributes=1”? Pin
Synetech25-Jan-14 11:06
memberSynetech25-Jan-14 11:06 
GeneralTitle spelling error Pin
the1freak29-May-08 7:03
memberthe1freak29-May-08 7:03 
GeneralRe: Title spelling error Pin
Abbas Ali Butt1-Jun-08 2:10
memberAbbas Ali Butt1-Jun-08 2:10 
GeneralRe: Title spelling error Pin
the1freak2-Jun-08 3:22
memberthe1freak2-Jun-08 3:22 
GeneralAfter that just make the .ini file hidden. Pin
Niiiissssshhhhhuuuuu29-May-08 4:57
memberNiiiissssshhhhhuuuuu29-May-08 4:57 
GeneralFind another program Pin
Mohsen Ahmadian29-May-08 4:16
memberMohsen Ahmadian29-May-08 4:16 
GeneralRe: Find another program Pin
Abbas Ali Butt1-Jun-08 2:45
memberAbbas Ali Butt1-Jun-08 2:45 
GeneralPlease fix formatting Pin
peterchen29-May-08 2:21
memberpeterchen29-May-08 2:21 
GeneralRe: Please fix formatting Pin
Padmaraj580323-Apr-13 18:08
memberPadmaraj580323-Apr-13 18:08 

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.

Posted 29 May 2008


11 bookmarked