Wallpaper changing in XP problem.


  • I'm writing a windows forms application to change desktop wallpapers. It works fine with Windows Vista and Windows 7, but that same code doesn't work on Windows XP. I'm really puzzled. Actually the key function doesn't perform it's job:

       [DllImport("user32.dll", CharSet = CharSet.Auto)]
            static extern int SystemParametersInfo(int uAction,
                int uParam, string lpvParam, int fuWinIni);

    That was declaration of the api function and this is the code that changes the wallpaper:
    RegistryKey rkWallPaper =
           Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
                string w = "2";
                string t = "0";
                // Sets the wallpaper style
                rkWallPaper.SetValue("WallpaperStyle", w);
                // Whether or not this wallpaper will be displayed as a tile
                rkWallPaper.SetValue("TileWallpaper", t);
                SystemParametersInfo(20, 0, filePath, 0x01 | 0x02);
    Why doesn't this code work on winddows xp? I checked in the registry, the wallpaper doens't get set to the new image but remains the same as it was, and on the desktop, instead of a new image, the old image dissappears, and a basic blue background color appears instead.
    Friday, June 05, 2009 5:37 PM


All replies

  • The API for changing wallpaper is IActiveDesktop::SetWallpaper. Call IActiveDesktop::ApplyChanges to apply the changes.
    If you have question about Windows Shell API, ask in the newsgroup.

    MSMVP VC++
    • Marked as answer by Stardust1611 Friday, June 05, 2009 6:42 PM
    • Unmarked as answer by Stardust1611 Friday, June 05, 2009 10:49 PM
    Friday, June 05, 2009 5:48 PM
  • Are you saying that SystemParametersInfo doesn't work with Windows XP?
    Friday, June 05, 2009 6:03 PM
  • SystemParametersInfo is suppose to work, too, though it as limitations like not supporting jpeg as backgrounds. 

    SystemParametersInfo's behavior on a particur Windows version is better discussed in the Application Compatibility for Windows Development forum.

    MSMVP VC++
    Friday, June 05, 2009 6:29 PM
  • Thank you Sheng, I found your suggestion described at length at this page: , and I'm going to test it. I suppose setting style and tiled properties works the same way, by setting the registry keys. I'll give it a try.
    Friday, June 05, 2009 6:42 PM
  • I tried with the source code from that page, but i received following error:

    Unable to cast COM object of type 'ScreenElf.ActiveDesktop' to interface type 'ScreenElf.IActiveDesktop'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{F490EB00-1240-11D1-9888-006097DEACF9}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    This is the line that caused the error:
    IActive = (IActiveDesktop)dummy;

    Can someone please take a look?
    Friday, June 05, 2009 6:58 PM
  • Search the Common Language Runtime forum with the error code.
    MSMVP VC++
    Friday, June 05, 2009 7:07 PM
  • I found out on the internet that IActiveDesktop is not any more supported in Vista but replaced by Windows Sidebar, and by the Gadget Platform in Windows 7. This means that this problem is still not solved. If anyone know how to get SystemParametersInfo working on Windows XP, please report.
    Friday, June 05, 2009 10:54 PM
  • There is an article on change wallpaper in the link below, it works wheni try it on windows XP

    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    • Marked as answer by Stardust1611 Saturday, June 06, 2009 7:14 AM
    Saturday, June 06, 2009 12:58 AM
  • Thank you kaymaf. Until this morning I didn't realize that SystemParametersInfo works only with BMP files. I wasted so much time testing and testing. I have seen this link you sent me, and it suggests saving jpg file to a bmp before setting it as a wallpaper, but this complicates things greatly for me, specially when rotating images automatically. Interestingly SystemParametersInfo works on Vista and Windows 7 with jpg files as well. If anyone has some other suggestion on how to avoid saving images to temporary files, please report.
    Saturday, June 06, 2009 7:14 AM
  • There is another article in the link below but the code is in but it will be easy to convert to c#.



    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Saturday, June 06, 2009 12:09 PM
  • Thank you. I already implemented the idea of saving temporary file, and it works fine. Now the program works with bmp, jpg, png and gif. Thank you very much.
    Saturday, June 06, 2009 2:08 PM