How to programatically restore desktop wallpaper to Slideshow and Windows Spotlight mode?

Antoine Gorin 40 Points de réputation
2024-07-30T12:08:16.55+00:00

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

HKCU\Control Panel\Desktop\Wallpaper      # to read the wallpaper image filepath
HKCU\Control Panel\Desktop\WAllpaperStyle # to read the wallpaper image style (fill, fit ...)
HKCU\Control Panel\Colors\Background      # to read the background color
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\BackgroundType # 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:

HKCU\Control Panel\Colors\Background # to restore the saved color
HKCU\Control Panel\Desktop\Wallpaper = "" # to not show any image
HKCU\Control Panel\Desktop\WallpaperStyle = 0
HKCU\Control Panel\Desktop\TileWallpaper = 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<File> 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.

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\SlideshowEnabled = 1 # Activate slideshow mode
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\SlideshowDirectoryPath = "My/Specific/Folder/Path" # Specifies the folder to scan for images
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\SlideshowTickCount = 60000 # Specifies the delay between two images
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers\BackgroundType = 2 # Specifies the slideshow mode

HKCU\Control Panel\Personalization\Desktop Slideshow\Interval = 60000 # For any reasons there is an other key to specify the delay between two images
HKCU\Control Panel\Personalization\Desktop Slideshow\Shuffle = 0 # Whether or not images should be displayed in random order

HKCU\Control Panel\Desktop\Wallpaper = "" # to not show any image
HKCU\Control Panel\Desktop\WallpaperStyle = 6 # apparently this could have a role in specifying slideshow mode
HKCU\Control Panel\Desktop\TileWallpaper = 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?

Windows 10
Windows 10
Système d’exploitation Microsoft qui s’exécute sur des ordinateurs personnels et des tablettes.
88 questions
C#
C#
Langage de programmation orienté objet et sécurisé au niveau des types, qui prend ses racines dans la famille des langages C et inclut la prise en charge de la programmation orientée vers les composants.
13 questions
{count} votes

1 réponse

Trier par : Le plus utile
  1. Nina Kalenderska (Concentrix International) 540 Points de réputation Fournisseur Microsoft
    2024-07-30T20:56:04.7766667+00:00

    Bonjour,

    Merci d'avoir contacté la communauté Q&A France.

    Pour plus d'informations, je partage la réponse à votre question reçue dans le forum anglais:

    https://learn.microsoft.com/en-us/answers/questions/1847953/how-to-restore-windows-desktop-wallpaper-to-slides

    Cordialement,

    Nina

    1 personne a trouvé cette réponse utile.
    0 commentaires Aucun commentaire

Votre réponse

Les réponses peuvent être marquées comme Réponses acceptées par l’auteur de la question, ce qui permet aux utilisateurs de connaître la réponse qui a résolu le problème de l’auteur.