This is verfied working on Windows XP, 7, 8, 8.1 and Windows 10. MessageBox.Show("There was a problem setting the wallpaper.") MessageBox.Show("Your wallpaper has been set to " + FilePath) It can also be used like this: if(Wallpaper.Set(FilePath, )) Then it can be used like the following: string FilePath = TxtFilePath.Text Note: Replace XXXNAMESPACEXXX with the default namespace of your project. SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, TempPath, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE) String TempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp") Public static bool Set(Image image, Style style) Public static bool Set(string filePath, Style style) Public static readonly UInt32 SPIF_SENDWININICHANGE = 0x02 Public static readonly UInt32 SPIF_UPDATEINIFILE = 0x01 Public static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14 Public static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni)
The important part is on the third line of this code ( (Path.GetFullPath(wpaper)) ).Īdd the foillowing class to your project using Microsoft.Win32 String tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp") The Set method works perfectly this way: public static void Set(string wpaper, Style style) I had to reuse more code from the accepted answer here.īasically the problem in XP was that it needed to use a bmp file, so I managed to convert a project resource to a bmp file using that previous example and a little of tweaking. Well, this is a bit awkward, but I'll answer my own question with what I found. When calling Wallpaper.Set("wpapername"), it gets the wallpaper from project resources. SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE)
Public static void Set(string wpaper, Style style) Static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni) My code looks like this: public sealed class Wallpaper It, curiously, sets the correct Wallpaper name inside the Desktop's properties dialog. I add that wallpaper as a resource, set its compile action as Content and Always copy. I've developed the code so it perfectly works in Windows 7, but apparently it's not the same for XP. I'd wish to set a wallpaper for Windows XP using C#.