Win10 use friends will find that every time the boot lock screen interface will have a different beautiful picture, these pictures are usually selected from excellent photography, very beautiful.

However, the system will automatically replace these pictures, so even the most beautiful pictures may be replaced after the next boot.

With Python, we can batch extract these beautiful lock screen images with a few simple lines of code. Set your favorite image as your desktop background so you don’t have to worry about replacing it.

Extracting principle

Windows 10 automatically downloads the latest lock screen wallpapers and saves them in a system folder. Path is C: \ Users \ \ AppData \ [username] Local \ Packages \ Microsoft Windows. ContentDeliveryManager_cw5n1h2txyewy \ LocalState \ Assets

Open this folder directly and there will be randomly named multiple files, each file is a picture. But because the file does not have an extension, it cannot be previewed. To avoid damaging the system files, and to get them into a previewable format, we copied them in Python with JPG as the extension.

The implementation code

import os, shutil
from datetime import datetime


# Use the wallpapers folder where this file is located as the directory to save your images
save_folder = dir_path = os.path.dirname(
	os.path.realpath(__file__)) + '\wallpapers'
# Dynamically obtain the location of the lock screen picture stored in the system
wallpaper_folder = os.getenv('LOCALAPPDATA') + (
	'\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy'
	'\LocalState\Assets')
# list all files
wallpapers = os.listdir(wallpaper_folder)
for wallpaper in wallpapers:
	wallpaper_path = os.path.join(wallpaper_folder, wallpaper)
	# Images smaller than 150KB are not lock screen images
	if (os.path.getsize(wallpaper_path) / 1024) < 150:
		continue
	wallpaper_name = wallpaper + '.jpg'
	save_path = os.path.join(save_folder, wallpaper_name)
	shutil.copyfile(wallpaper_path, save_path)
	print('Save wallpaper ' + save_path)
Copy the code

Firstly, determine the location of the folder where the lock screen pictures are stored in the system. Since the folder is located in the user’s personal folder, the user name of each user is different, so we need to dynamically obtain the path through the LOCALAPPDATA variable of the system. The code will save the extracted images in the WallPapers folder, so there is no wallpapers folder in the directory of the code file, you will need to create one manually.

Execute the Python code above and open the wallPapers folder to see the extracted lock screen image.

Focus on Python private dishes