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);
}
}
}
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.