Files
winutil/functions/private/Invoke-WinUtilNumLock.ps1
T

32 lines
1.2 KiB
PowerShell
Raw Normal View History

+1
2023-11-14 15:45:48 -06:00
function Invoke-WinUtilNumLock {
<#
.SYNOPSIS
Disables/Enables NumLock on startup
.PARAMETER Enabled
Indicates whether to enable or disable Numlock on startup
#>
Param($Enabled)
try {
if ($Enabled -eq $false) {
+1
2023-11-14 15:45:48 -06:00
Write-Host "Enabling Numlock on startup"
$value = 2
} else {
+1
2023-11-14 15:45:48 -06:00
Write-Host "Disabling Numlock on startup"
$value = 0
}
2024-06-17 20:16:40 -07:00
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
2024-08-06 13:41:31 -05:00
$HKUPath = "HKU:\.Default\Control Panel\Keyboard"
$HKCUPath = "HKCU:\Control Panel\Keyboard"
Set-ItemProperty -Path $HKUPath -Name InitialKeyboardIndicators -Value $value
Set-ItemProperty -Path $HKCUPath -Name InitialKeyboardIndicators -Value $value
+1
2023-11-14 15:45:48 -06:00
}
Catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
} catch [System.Management.Automation.ItemNotFoundException] {
+1
2023-11-14 15:45:48 -06:00
Write-Warning $psitem.Exception.ErrorRecord
} catch {
+1
2023-11-14 15:45:48 -06:00
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}