8

How can I programmatically change/set the lock screen background image (using VB.NET, C# or Visual C++)? I am using Win 10 Pro and have Visual Studio 2017 Pro.

I've had a look online but most solutions don't seem to work. For example:

  1. Both Change Win 10 Lockscreen Image Mutiple Times C# WPF and Change Windows Lock Screen background image in C# provide sample code but the imports System.Windows.Media.Imaging, Windows.Storage, Windows.Storage.Streams, Windows.System.UserProfile cannot be found when I paste the code. Do I need to add specific references?
  2. Lock screen personalization sample looks very promising but upon opening the solution/project file, Visual Studio throws an error saying that the provided format is unreadable.

Most sources (also Windows Dev Center - LockScreen Class) seem to suggest
Windows.System.UserProfile.LockScreen.SetImageFileAsync(file);
but I am apparently missing the specific namespace/import/package to make it run.

Any help would be appreciated.

ThomasT
  • 201
  • 2
  • 7
  • 1
    in visual studio you can resolve the namespace by rightclicking the line and selecting the resolve. if the code needs a namespace. – Albert Laure Aug 10 '18 at 08:29
  • I've tried this, but it doesn't work like that. https://i.stack.imgur.com/uVmaa.png – ThomasT Aug 10 '18 at 08:33
  • Looks like you are using an ConsoleApplication but your links are for UWP and WPF – David Sdot Aug 10 '18 at 08:40
  • 1
    Which would be the right one to use? I see many WPF, but no UWP. https://i.stack.imgur.com/yxCz4.png – ThomasT Aug 10 '18 at 08:47
  • Have you got the Windows 10 SDK installed? Also, there's a Win10 version of the Lock screen personalisation sample [here](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Personalization) – dkwarr87 Aug 10 '18 at 09:41
  • @dkwarr87 Thanks. I have installed the SDK now. https://i.stack.imgur.com/KQhoO.png And the link you posted does compile, but I cannot start it. https://i.stack.imgur.com/S5neo.png – ThomasT Aug 10 '18 at 11:25

3 Answers3

11

I've found an easier way using this question Windows 10 Pro lockscreen mass change. All I need to do is set the registry entries under

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP

  • DesktopImagePath
  • DesktopImageUrl
  • LockScreenImagePath
  • LockScreenImageUrl

to the path of the desired picture, which works without UWP or WPF.

a3li
  • 3
  • 1
ThomasT
  • 201
  • 2
  • 7
1

As alluded to in my comment, the Windows.System.UserProfile namespace is part of the UWP platform and requires having the Windows 10 SDK installed to utilize.

You can install the SDK by running the Visual Studio Installer, click "Modify" and then choose the "Universal Windows Platform development" workload, or choose the SDK from the list of "Individual Components". More details can be found here.

You may be able to use the library from a desktop .NET app as mentioned in this question How to Interop with Windows Runtime in .NET 4.5 and this link from the answer, but there's no guarantee that Microsoft will continue to allow that so you're probably better off developing using the UWP.

There is a sample from Microsoft for Lock Screen Personalisation on Windows 10 on GitHub here.

dkwarr87
  • 204
  • 2
  • 10
1

ImageGlass, an open-source image viewer, provides a command-line utility to change the Windows LockScreen image: igcmdWin10.exe

Usage: igcmdWin10.exe setlockimage "C:\image.jpg"

Extract it from the .zip release on their Github repository

ImageGlass official documentation for reference.

Lucas
  • 11
  • 2