Created
April 9, 2021 10:24
-
-
Save sotolf2/296c88295f0aba22d3033bfbc0e19d81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[parameter(Mandatory=$false,Position=0)] | |
[string]$pic = 'Lock' | |
) | |
# When using, the file names must change. | |
# if the filename exists at the Network location and the Temp location, it is assumed the script already ran. | |
# To run again simply change the file names or delete the Temp location's contents. | |
# Designed this way to not download pictures, and wait for script every reboot. | |
# *** Network location of file - Somewhere Domain Users (and Domain Computers?) read access. | |
# *** Use "PSScriptRoot" to use the same location as script file. | |
$networkLocation = "$PSScriptRoot" | |
# *** Local Location to store the lockscreen pictures, note this isn't where windows reads the lockscreen. It's just a temp location. | |
$tempLocation = 'C:\Lockscreen' | |
# Path for the registry keys that we're going to set | |
$PersonalizationRegistryKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP" | |
# If the network files can't be reached, exit. | |
if( (!(Test-Path -Path "$networkLocation\${pic}.jpg")) -or (!(Test-Path "$networkLocation\${pic}.png")) ){ | |
Exit | |
} ELSE { | |
# If the temp location doesn't exist create it. | |
if(!(Test-Path -Path $tempLocation)){New-Item -Path $tempLocation -type Directory} | |
# If the files do not exist copy them down then set as Lockscreen, else exit. | |
if( (!(Test-Path -Path "$tempLocation\${pic}.jpg")) -or (!(Test-Path -Path "$tempLocation\${pic}.png")) ){ | |
Remove-Item -Path "$tempLocation\*.*" | |
Copy-Item "$networkLocation\${pic}.jpg" -Destination "$tempLocation\${pic}.jpg" | |
Copy-Item "$networkLocation\${pic}.png" -Destination "$tempLocation\${pic}.png" | |
takeown /f C:\Windows\Web\screen | |
takeown /f C:\Windows\Web\screen\*.* /R | |
icacls C:\Windows\Web\screen /grant Administrators:F /T /C | |
takeown /f C:\ProgramData\Microsoft\Windows\SystemData | |
takeown /f C:\ProgramData\Microsoft\Windows\SystemData /R /D Y | |
icacls C:\ProgramData\Microsoft\Windows\SystemData /grant Administrators:F /T /C | |
Remove-Item -path "C:\ProgramData\Microsoft\Windows\SystemData" -Recurse -Force | |
$windowsLocation = 'C:\Windows\Web\Screen' | |
$images = 'img100','img101','img102','img103','img104','img105' | |
$images | % { | |
Copy-Item -Path "$tempLocation\${pic}.jpg" -Destination "$windowsLocation\${_}.jpg" -Force | |
Copy-Item -Path "$tempLocation\${pic}.png" -Destination "$windowsLocation\${_}.png" -Force | |
} | |
} | |
if(!(Test-Path $PersonalizationRegistryKeyPath)) { | |
New-Item -Path $PersonalizationRegistryKeyPath -Force | Out-Null | |
} | |
# Create new itemproperties or set them if they already exist | |
New-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImageStatus" -Value "1" -PropertyType DWORD -Force | Out-Null | |
New-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImagePath" -Value "$tempLocation\${pic}.jpg" -PropertyType STRING -Force | Out-Null | |
New-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImageUrl" -Value "$tempLocation\${pic}.jpg" -PropertyType STRING -Force | Out-Null | |
Set-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImageStatus" -Value "1" -PropertyType DWORD -Force | Out-Null | |
Set-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImagePath" -Value "$tempLocation\${pic}.jpg" -PropertyType STRING -Force | Out-Null | |
Set-ItemProperty -Path $PersonalizationRegistryKeyPath -Name "LockScreenImageUrl" -Value "$tempLocation\${pic}.jpg" -PropertyType STRING -Force | Out-Null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment