1

How do I set the lock screen from 'windows spotlight' to 'photo' and then set the photo to a specific image.

Here is what I tried:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization' -Name LockScreenImage -value "C:\Custom-Folder\wallpaper.jpg"

it gives me an error and says the Path does not exist.

Here is the error message:

Set-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization' because it
does not exist.
At line:1 char:1
+ Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Per ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (HKLM:\SOFTWARE\...Personalization:String) [Set-ItemProperty], I
   temNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

2
  • Note: This question is on topic in terms of content, OP is not asking how to set this, they are inquiring about the error received when setting the registry key property value.
    – codewario
    Oct 30, 2021 at 4:55
  • OP what is the exact error you are getting?
    – codewario
    Oct 30, 2021 at 4:55

2 Answers 2

1

You need to ensure the registry key exists and if not create it first.

Edit

Thanks to mklement0's comment it is clear we shouldn't use New-Item -Force on a registry key because of the risk all content of an existing key will get destroyed.

That means we need a test to see if the key exists

$regKey = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization'
# create the key if it doesn't already exist
if (!(Test-Path -Path $regKey)) {
   $null = New-Item -Path $regKey
}

# now set the registry entry
Set-ItemProperty -Path $regKey -Name LockScreenImage -value "C:\Custom-Folder\wallpaper.jpg"

Because this is in HKEY_LOCAL_MACHINE you need to run this code as Administrator.

4
  • 1
    Instead of discarding the New-Item result, one could use it to streamline the code: New-Item -Path $regKey -Force | Set-ItemProperty -Name LockScreenImage -value "C:\Custom-Folder\wallpaper.jpg".
    – zett42
    Oct 30, 2021 at 11:08
  • 1
    Unfortunately, using New-Item -Force with a registry key effectively wipes out any existing values of a preexisting key (the key is apparently re-created) - which is arguably a bug, given that a registry key is akin to a file-system directory, whose content should be preserved with -Force, not a file - see GitHub issue #5444; /cc @zett42
    – mklement0
    Oct 30, 2021 at 18:29
  • 1
    @mklement0 Thanks for this warning. I wasn't aware of this bug before (always testing in the registry with dummy keys luckily..). Changed that in my answer now.
    – Theo
    Oct 30, 2021 at 20:16
  • Thanks for updating, @Theo. Yes, it's an easy bug to miss, but with potentially destructive consequences - I hope they'll fix it some day...
    – mklement0
    Oct 30, 2021 at 21:43
0

For anyone who ended up on this page looking for why that path can't be found, it is because the actual path is

HKLM:\SOFTWARE\Policies\Microsoft\Windows\CurrentVersion\Personalization. 

'CurrentVersion' is missing from the original path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.