# Disable_AutoLock.ps1
function changeAutoLock{
param (
[Switch]$disable,
[Switch]$enable
)
$registryHive = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization"
$registryKey="NoLockScreen"
$keyItem = Get-ItemProperty -Path $registryHive -Name $registryKey -ErrorAction SilentlyContinue
$keyValue = $keyItem.NoLockScreen
If($enable)
{
If($keyValue){
#Remove item property
Remove-Item -Path $registryHive -Recurse -Confirm:$false | Out-Null
Write-Host "Enabled lock screen successfully."
}Else{
Write-Host "Lock screen has already been enabled prior."
}
}else{
If($keyValue){
Write-Host "Lock screen has already been disabled."
}Else{
New-Item -Path $registryHive -ErrorAction SilentlyContinue | Out-Null
New-ItemProperty -Path $registryHive -Type "DWORD" -Name "NoLockScreen" -Value 1 | Out-Null
Write-Host "Disabled lock screen successfully."
}
}
}
changeAutoLock -disable
Categories: