Context
I have a console application in .Net 6 C# that changes the current user’s desktop wallpaper to an image for a given time. I backup the current wallpaper configuration of the user by reading the registry. At the end of the givent time, I would like to restore the wallpaper configuration the user had at the beginning.
I managed to restore the image mode and color mode but I didn’t managed to restore Slideshow nor Windows Spotlight mode. Ideally I’d like it to work on Windows 10, 11, Windows Server 2016, 2019 and 2022 (I realize there might be differences between thos environments).
The keys I use to read the curent configuration
HKCUControl PanelDesktopWallpaper # to read the wallpaper image filepath
HKCUControl PanelDesktopWAllpaperStyle # to read the wallpaper image style (fill, fit ...)
HKCUControl PanelColorsBackground # to read the background color
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerWallpapersBackgroundType # to read the background mode (image, color, slideshow, windows spotlight)
Solutions for restoring Image and colors
To restore the image I used the IDesktopWallpaper interface and to restore colors, I used registry keys:
HKCUControl PanelColorsBackground # to restore the saved color
HKCUControl PanelDesktopWallpaper = "" # to not show any image
HKCUControl PanelDesktopWallpaperStyle = 0
HKCUControl PanelDesktopTileWallpaper = 0
I then called the following function to refresh the desktop by reading the registry.
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
Solutions tried for restoring Slideshow
I tried 2 solutions: using the IDesktopWallpaper interface with SetSlideshow() and setting some registry keys.
For the IDesktopWallpaper.SetSlideshow, I don’t know how I can transform from a List to a IShellItemArray. (see https://learn.microsoft.com/fr-fr/windows/win32/api/shobjidl_core/nf-shobjidl_core-idesktopwallpaper-setslideshow)
For the registry solution, I tried setting the following registry keys but the wallpaper simply switch from image mode to color mode.
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerWallpapersSlideshowEnabled = 1 # Activate slideshow mode
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerWallpapersSlideshowDirectoryPath = "My/Specific/Folder/Path" # Specifies the folder to scan for images
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerWallpapersSlideshowTickCount = 60000 # Specifies the delay between two images
HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerWallpapersBackgroundType = 2 # Specifies the slideshow mode
HKCUControl PanelPersonalizationDesktop SlideshowInterval = 60000 # For any reasons there is an other key to specify the delay between two images
HKCUControl PanelPersonalizationDesktop SlideshowShuffle = 0 # Whether or not images should be displayed in random order
HKCUControl PanelDesktopWallpaper = "" # to not show any image
HKCUControl PanelDesktopWallpaperStyle = 6 # apparently this could have a role in specifying slideshow mode
HKCUControl PanelDesktopTileWallpaper = 0
Are there any other API that exists that I didn’t mention? Am I missing something in the slideshow configuration?
Bonus Question: Is it possible to restore the Windows spotlight mode for wallpaper?