Sync Desktop and Lock-screen Wallpaper?

Page 3 of 3 FirstFirst 123

  1. Posts : 42,983
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #21

    - the 3rd party prog idea was just a thought if nothing else worked out...
      My Computers


  2. Posts : 17,838
    Windows 10
       #22

    Mine synced every once in a while but it's very random,

    plus the fact that Screen Saver duration settings are only Slow, Medium and Fast, whereas Desktop Background has more incremental options.

    Sync Desktop and Lock-screen Wallpaper?-000758.png Sync Desktop and Lock-screen Wallpaper?-untitled.png
      My Computer


  3. Posts : 1
    na
       #23

    Solution.


    Old thread but here is a PowerShell script that achieves this. Add it as a scheduled task running under your user account (which must be an administrator), tick "run with highest privileges", with the trigger "At Logon" and/or "At Workstation Unlock"

    The script takes ownership and sets read permissions on the files used for the lock screen and determines the correct lock screen image based on the screen resolution height of your primary monitor and the last modified file.

    I haven't tested this extensively (at all), but it works in my environment, modify to your requirements.


    Code:
    # Set desktop background to lock screen.
    
    
    # Set-WallPaper Function from https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/
    Function Set-WallPaper {
     
    <#
     
        .SYNOPSIS
        Applies a specified wallpaper to the current user's desktop
        
        .PARAMETER Image
        Provide the exact path to the image
     
        .PARAMETER Style
        Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span)
      
        .EXAMPLE
        Set-WallPaper -Image "C:\Wallpaper\Default.jpg"
        Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit
      
    #>
     
    param (
        [parameter(Mandatory=$True)]
        # Provide path to image
        [string]$Image,
        # Provide wallpaper style that you would like applied
        [parameter(Mandatory=$False)]
        [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')]
        [string]$Style
    )
     
    $WallpaperStyle = Switch ($Style) {
      
        "Fill" {"10"}
        "Fit" {"6"}
        "Stretch" {"2"}
        "Tile" {"0"}
        "Center" {"0"}
        "Span" {"22"}
      
    }
     
    If($Style -eq "Tile") {
     
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
     
    }
    Else {
     
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
     
    }
     
    Add-Type -TypeDefinition @" 
    using System; 
    using System.Runtime.InteropServices;
      
    public class Params
    { 
        [DllImport("User32.dll",CharSet=CharSet.Unicode)] 
        public static extern int SystemParametersInfo (Int32 uAction, 
                                                       Int32 uParam, 
                                                       String lpvParam, 
                                                       Int32 fuWinIni);
    }
    "@ 
      
        $SPI_SETDESKWALLPAPER = 0x0014
        $UpdateIniFile = 0x01
        $SendChangeEvent = 0x02
      
        $fWinIni = $UpdateIniFile -bor $SendChangeEvent
      
        $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
    }
     
    
    
    
    
    
    # Variables
    $Resolution = Get-WmiObject -Class Win32_DesktopMonitor | select-object -ExpandProperty ScreenHeight
    
    
    # Set permissions
    $lockScreenPath = "C:\ProgramData\Microsoft\Windows\SystemData\"
    
    $folders = Get-ChildItem -path $lockScreenPath -recurse -Depth 4
    
    foreach ($folder in $folders){
    
    	write-host "Setting permissions on" $folder
    	$acl = Get-Acl $folder.FullName
    	
    	if ($acl) { 
    	
    		$acl = Get-Acl $folder.FullName
    		$person = [System.Security.Principal.NTAccount]$env:UserName          
    		$access = [System.Security.AccessControl.FileSystemRights]"ReadAndExecute"
    		$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
    		$propagation = [System.Security.AccessControl.PropagationFlags]"None"
    		$type = [System.Security.AccessControl.AccessControlType]"Allow"
    		
    		if ($folder.PsIsContainer) {		
    		
    			takeown /f $Folder.FullName /r
    			$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($person,$access,$inheritance,$propagation,$type)
    		
    		} else {
    		
    			$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($person,$access,$type)
    		
    		}
    		
    		$acl.AddAccessRule($rule)
    		$acl | Set-Acl	
    		
    	}
    	
    }
    
    # Finds the correct file (hopefully!).
    $LockScreenImage = Get-ChildItem $folders.FullName -File | where {$_.FullName -like "*$Resolution*"} | sort LastWriteTime | select -last 1
    Copy-item $LockScreenImage.FullName -Destination "c:\programdata\background.jpg"
    
    # Setting the WallPaper
    Set-WallPaper -Image "c:\programdata\background.jpg" -Style Fit
    - - - Updated - - -

    updated.

    Code:
    # Set desktop background to lockscreen.
    
    
    # Set WallPaper Function from https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/
    Function Set-WallPaper {
     
    <#
     
        .SYNOPSIS
        Applies a specified wallpaper to the current user's desktop
        
        .PARAMETER Image
        Provide the exact path to the image
     
        .PARAMETER Style
        Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span)
      
        .EXAMPLE
        Set-WallPaper -Image "C:\Wallpaper\Default.jpg"
        Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit
      
    #>
     
    param (
        [parameter(Mandatory=$True)]
        # Provide path to image
        [string]$Image,
        # Provide wallpaper style that you would like applied
        [parameter(Mandatory=$False)]
        [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')]
        [string]$Style
    )
     
    $WallpaperStyle = Switch ($Style) {
      
        "Fill" {"10"}
        "Fit" {"6"}
        "Stretch" {"2"}
        "Tile" {"0"}
        "Center" {"0"}
        "Span" {"22"}
      
    }
     
    If($Style -eq "Tile") {
     
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
     
    }
    Else {
     
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
        New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
     
    }
     
    Add-Type -TypeDefinition @" 
    using System; 
    using System.Runtime.InteropServices;
      
    public class Params
    { 
        [DllImport("User32.dll",CharSet=CharSet.Unicode)] 
        public static extern int SystemParametersInfo (Int32 uAction, 
                                                       Int32 uParam, 
                                                       String lpvParam, 
                                                       Int32 fuWinIni);
    }
    "@ 
      
        $SPI_SETDESKWALLPAPER = 0x0014
        $UpdateIniFile = 0x01
        $SendChangeEvent = 0x02
      
        $fWinIni = $UpdateIniFile -bor $SendChangeEvent
      
        $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
    }
     
    
    
    
    
    
    # Variables
    $Resolution = Get-WmiObject -Class Win32_DesktopMonitor | select-object -ExpandProperty ScreenHeight
    
    
    # Set permissions
    $lockScreenPath = "C:\ProgramData\Microsoft\Windows\SystemData\"
    
    takeown /f $lockScreenPath /r /D Y
    
    $folders = Get-ChildItem -path $lockScreenPath -recurse -Depth 4
    
    foreach ($folder in $folders){
    
    	write-host "Setting permissions on" $folder
    	$acl = Get-Acl $folder.FullName
    	
    	if ($acl) { 
    	
    		$acl = Get-Acl $folder.FullName
    		$person = [System.Security.Principal.NTAccount]$env:UserName          
    		$access = [System.Security.AccessControl.FileSystemRights]"ReadAndExecute"
    		$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
    		$propagation = [System.Security.AccessControl.PropagationFlags]"None"
    		$type = [System.Security.AccessControl.AccessControlType]"Allow"
    		
    		if ($folder.PsIsContainer) {		
    		
    			takeown /f $Folder.FullName /r
    			$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($person,$access,$inheritance,$propagation,$type)
    		
    		} else {
    		
    			$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($person,$access,$type)
    		
    		}
    		
    		$acl.AddAccessRule($rule)
    		$acl | Set-Acl	
    		
    	}
    	
    }
    
    # Finds the correct file (hopefully!).
    $LockScreenImage = Get-ChildItem $folders.FullName -File | where {$_.FullName -like "*$Resolution*"} | sort LastWriteTime | select -last 1
    Copy-item $LockScreenImage.FullName -Destination "c:\programdata\background.jpg"
    
    # Setting the WallPaper
    Set-WallPaper -Image "c:\programdata\background.jpg" -Style Fit
      My Computer


  4. Posts : 1
    Windows 10
       #24

    Hi Nickb167,
    Im using WinDynamicDesktop to change my desktop wallpaper through the day and I also wanted to sync with my lock screen image. How should I change your script to work in this case?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:52.
Find Us




Windows 10 Forums