0

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?

Kumar M
  • 994
  • 6
  • 21
  • 1
    Have you tried creating/editing this key with regedit? does the key get set at all? Also is your application 64bit? – TheGeneral Jan 11 '19 at 06:49
  • I was running that code programmatically and trying. Now I tried to create the key in regedit after seeing your comment(I am new to WPF) but I don't see PersonalizationCSP under CurrentVersion in my system, only Personalization is there. – Kumar M Jan 11 '19 at 07:33
  • @TheGeneral Will this Registry solution support in all Windows 10 OS? – Kumar M Jan 11 '19 at 07:35
  • You should read the docs about Registry and RegistryKey – Sir Rufo Jan 11 '19 at 08:24
  • I think I would approach this by using windows to manually set a picture as lock screen. Then search my registry using regedit for that file name ( make sure it will be unique ) and see what is set. It's much more likely to be a user setting than machine. I think an app would need to run as admin to change the machine branch. – Andy Jan 11 '19 at 11:00
  • Checkout this PowerShell script. It could help you to write the same in C#. https://github.com/pwujczyk/ProductivityTools.PSSetLockScreen/blob/master/ProductivityTools.PSSetLockScreen/ProductivityTools.PSSetLockScreen.psm1 – Pawel Wujczyk May 04 '20 at 15:00

1 Answers1

2

Your code creates the wrong key in the registry. Also instead of HKEY_LOCAL_MACHINE you use HKEY_CURRENT_USER. 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.