How to change Windows Lock Screen background without creating a UWP app?

Moying 0 Reputation points
2025-03-21T03:46:45.3133333+00:00

I need to programmatically change the Windows Lock Screen background, but my application's logic is quite complex, and it can't be achieved using the built-in Windows functionalities.

I know that it's possible to create a UWP app and use the Windows.System.UserProfile.LockScreen API to change the Lock Screen background. However, this API seems limited to the UWP runtime environment only. For example, I've tried using Python's WinRT or WinSDK packages, but none of them successfully invoked this API.

Is there any alternative way to achieve this functionality without relying on a UWP app—for instance, through a Python script or by creating a WPF application? I'd like to know if this is feasible.

Thanks!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,853 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hongrui Yu-MSFT 5,255 Reputation points Microsoft External Staff
    2025-03-21T07:59:22.9466667+00:00

    Hi, @Moying. Welcome to Microsoft Q&A. 

    Refer to the following method:

    1.Create a WPF Application project (assuming you are creating a .net 8 version).

    2.Refer to the documentation, open your csproj file, and modify the TargetFramework according to your target operating system. (Here, it is assumed that your target operating system is Windows 11, version 24H2)

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows10.0.26100.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <UseWPF>true</UseWPF>
      </PropertyGroup>
    
    </Project>
    

    3.Rebuild your project via Rebuild

    4.Edit the code in MainWindow.xaml.cs to set the lock screen picture.

        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                this.Loaded += Window_Loaded;
            }
    
            private async void Window_Loaded(object sender, RoutedEventArgs e)
            {
                string FilePath = @"The image you want to set";
                Windows.Storage.StorageFile imageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(FilePath);
                await Windows.System.UserProfile.LockScreen.SetImageFileAsync(imageFile);
            }
        }
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.