Bart Simons

wallpapers

A 1 post collection


Windows 10 Lock Screen Wallpapers On Your Desktop

 •  Filed under windows 10, spotlight, lock screen, wallpapers, on desktop, powershell

If you use Windows 10, you probably know about Windows Spotlight, the feature that automatically fetches beautiful wallpapers for on your lockscreen. But, we're not left out with any option to set the desktop wallpaper to Windows Spotlight photos by default! Luckily, I've written a really nifty little PowerShell script that actually gets the job done.

<# LockScreenWallpaperToDesktop.ps1 #>

$SystemWallpaperCode = @"
using System.Runtime.InteropServices;  
public class Wallpaper  
{
    public const int SetDesktopWallpaper = 20;
    public const int UpdateIniFile = 0x01;
    public const int SendWinIniChange = 0x02;
    [DllImport(`"user32.dll`", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
    public static void SetWallpaper ( string path )
    {
        SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
    }
}
"@

Add-Type -TypeDefinition $SystemWallpaperCode

$MinimumFileByteSize = 320000

$LockScreenWallpapersLocation = "$env:LOCALAPPDATA\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"

$WallpaperFile = (Get-ChildItem $LockScreenWallpapersLocation | where { $_.Length -gt $MinimumFileByteSize } | Get-Random)[0]

$wallpaperFile=$WallpaperFile.Name

Copy-Item "$LockScreenWallpapersLocation\$wallpaperFile" "$env:USERPROFILE\wallpaper.png"

[Wallpaper]::SetWallpaper("$env:USERPROFILE\wallpaper.png")