0

I am building a custom Windows Shell for Windows 2016, in C#, to replace Windows Explorer.

One of the functionalities of the new shell is to set the Windows Background/Wallpaper using a Windows (user32.dll) function called SystemParametersInfo(). However, the function only works when the Windows Explorer is running.

I noticed this behavior was introduced since Windows 8 and Windows 2012. So my question is: How I can change the Windows Background when the explorer.exe process is not running?

    public class WindowsBackgroup
{
    const int SET_DESKTOP_BACKGROUND = 20;
    const int UPDATE_INI_FILE = 1;
    const int SEND_WIN_INI_CHANGE = 2;

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    //https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa?redirectedfrom=MSDN
    static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
    public static void Set(string imageFile)
    {
        SystemParametersInfo(SET_DESKTOP_BACKGROUND, 0, imageFile, UPDATE_INI_FILE | SEND_WIN_INI_CHANGE);
    }

    static void Main(string[] args)
    {
        string appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        string imageFile = appDataLocal + "\\Sysinternals\\BGInfo\\BGInfo.bmp";
        Set(imageFile);
    }
}

}

3
  • Would Windows GDI the way to go with my story? Maybe user32.dll always requires explorer? learn.microsoft.com/en-us/windows/win32/gdi/… Commented Feb 17, 2021 at 20:28
  • I think I cant change the Windows Background using GDI, but I can create a full window as background and paint it. What do you think? Commented Feb 18, 2021 at 2:06
  • Yes, as you might expect, SystemParametersInfo(SPI_SETDESKWALLPAPER,...) cannot set the desktop background when explorer.exe is not running. Creating a thread to display full-screen windows without borders may be another option, but you will need to redesign the entire windows desktop, icons, taskbars, file, etc., which will be a difficult process. Commented Feb 18, 2021 at 2:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.