Kumar M
Kumar M

Reputation: 1014

How to set Windows 10 and above Lock Screen Wallpaper from WPF?

I want to set Lock Screen Wallpaper of Windows 10 and above from WPF application. I have searched and found the following links are useful.

https://stackoverflow.com/a/51785913/5523095

https://superuser.com/a/1274588

Based on the suggestion from the above answers I am trying to change the lock screen wallpaper using the following code.

RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP", true);           
key.SetValue(@"LockScreenImagePath", @"C:\Users\kumarm\Desktop\Wall.png");
key.SetValue(@"LockScreenImageUrl", @"C:\Users\kumarm\Desktop\Wall.png");
key.SetValue("LockScreenImageStatus", 1, RegistryValueKind.DWord);
key.Flush();

But the lock screen wallpaper is not changing. Am I doing anything wrong?

Upvotes: 0

Views: 1612

Answers (1)

Your code creates the wrong key in the registry. Also, instead of HKEY_LOCAL_MACHINE you have used HKEY_CURRENT_USER.

It should be like this:

RegistryKey key = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP", true);
key.SetValue(@"LockScreenImagePath", @"C:\Images\image.jpg");
key.SetValue(@"LockScreenImageUrl", @"C:\Images\image.jpg");
key.SetValue(@"LockScreenImageStatus", 1, RegistryValueKind.DWord);
key.Flush();

This code does work, but after that you cannot change the lock screen image in Windows settings - the possibility is blocked with the reference "Some of these settings are managed by your organization", which can be fixed by deleting registry keys, or by setting empty "LockScreenImagePath" and "LockScreenImageUrl" values in the registry.

Upvotes: 2

Related Questions