How to Set Num Lock to On at Startup in Batch Script
On many Windows machines, especially in enterprise environments, the Num Lock key defaults to "Off" when the computer boots up or a user reaches the login screen. This forces users to manually press Num Lock before typing their numeric password or PIN, which is a minor but persistent annoyance. For data entry workstations or kiosk setups where the numeric keypad is essential, ensuring Num Lock is always enabled at startup is a critical configuration step.
In this guide, we will explore how to configure Windows to automatically enable Num Lock at boot via registry modification in a Batch Script.
The Registry Key
The initial Num Lock state at the Windows login screen is controlled by a registry value in the default user profile:
HKU\.DEFAULT\Control Panel\Keyboard
Value Name: InitialKeyboardIndicators
Type: REG_SZ
The value is a string number that represents a bitmask of keyboard indicator flags:
| Value | Meaning |
|---|---|
0 | All indicators OFF |
1 | Caps Lock ON |
2 | Num Lock ON |
4 | Scroll Lock ON |
Values can be combined (e.g., 3 = Caps Lock + Num Lock ON). In practice, the most common desired setting is 2 (only Num Lock ON) or 2147483650 (a special value used by some Windows versions for the same effect).
Method 1: Setting Num Lock On via the Registry
@echo off
setlocal
:: Verify Admin Rights
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Administrator privileges required.
pause
exit /b 1
)
echo Setting Num Lock to ON at startup...
:: Set the InitialKeyboardIndicators for the .DEFAULT user profile
:: Value "2" = Num Lock ON
REG ADD "HKU\.DEFAULT\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2" /f >nul
if %errorlevel% == 0 (
echo [SUCCESS] Num Lock will be ON at the login screen after next reboot.
) else (
echo [ERROR] Failed to update registry.
)
pause
Why .DEFAULT and Not HKCU?
The .DEFAULT hive under HKU (HKEY_USERS) controls settings for the Windows login screen and system accounts. It is evaluated before any user logs in. If you modify HKCU\Control Panel\Keyboard\InitialKeyboardIndicators, it only affects the currently logged-in user's session, not the login screen itself.
Method 2: Setting Num Lock for All User Profiles
To ensure Num Lock is on for every user who logs into the machine (not just at the login screen), you should update both the .DEFAULT profile and all existing user profiles.
@echo off
setlocal enabledelayedexpansion
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Admin required.
pause
exit /b 1
)
echo Enabling Num Lock for all user profiles...
:: 1. Set for the login screen (.DEFAULT)
REG ADD "HKU\.DEFAULT\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2" /f >nul
echo [OK] Login screen (.DEFAULT^)
:: 2. Set for the current user
REG ADD "HKCU\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2" /f >nul
echo [OK] Current user (HKCU^)
:: 3. Enumerate all loaded user SIDs and update them
for /f "tokens=*" %%S in ('reg query HKU 2^>nul ^| findstr /r "S-1-5-21-"') do (
REG ADD "%%S\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2" /f >nul 2>&1
echo [OK] Updated: %%S
)
echo.
echo [SUCCESS] Num Lock set to ON for all profiles.
echo Changes take effect at next login or reboot.
pause
Understanding the SID Enumeration
The for loop queries HKU (HKEY_USERS) for all loaded user hives. Each user profile is identified by its Security Identifier (SID), which starts with S-1-5-21-. By iterating through these, we update every known user on the system in a single pass.
Method 3: The Windows 10/11 Value Variation
Some versions of Windows 10 and 11 use the value 2147483650 instead of 2 for the same Num Lock behavior. This is 0x80000002 in hexadecimal, which sets the high bit as a flag for "persist across reboots."
If the standard value 2 does not work on your specific Windows build, try the extended value:
@echo off
setlocal
net session >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Admin required.
pause
exit /b 1
)
echo Applying Windows 10/11 extended Num Lock setting...
:: Use the extended value
REG ADD "HKU\.DEFAULT\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2147483650" /f >nul
REG ADD "HKCU\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2147483650" /f >nul
echo [SUCCESS] Extended Num Lock setting applied.
pause
If you are unsure which value to use, set both 2 and 2147483650 in sequence. The system will use whichever it recognizes, and the other will be harmlessly ignored if overwritten. In practice, 2147483650 is the most reliable choice for Windows 10 and 11.
BIOS/UEFI Setting
It is worth noting that many BIOS/UEFI firmware setups have their own "Num Lock on Boot" toggle. If your BIOS is set to "Num Lock OFF," it may override the Windows registry setting before Windows even loads.
To fully guarantee Num Lock at boot:
- Enable "Num Lock on Boot" in the BIOS/UEFI setup.
- Set the
InitialKeyboardIndicatorsregistry value as described above.
This two-layer approach covers both the pre-Windows boot phase and the Windows login screen.
Toggling Num Lock Programmatically in the Current Session
If you need to force Num Lock ON during a running script (not just at next boot), you can simulate a keypress using PowerShell.
@echo off
setlocal
echo Forcing Num Lock ON in the current session...
:: Check if Num Lock is currently off, and press it if so
powershell -noprofile -command ^
"if (-not [System.Console]::NumberLock) {" ^
" $wsh = New-Object -ComObject WScript.Shell;" ^
" $wsh.SendKeys('{NUMLOCK}');" ^
" Write-Host '[OK] Num Lock toggled ON.'" ^
"} else {" ^
" Write-Host '[OK] Num Lock is already ON.'" ^
"}"
pause
Common Mistakes
The Wrong Way: Using REG_DWORD Instead of REG_SZ
:: WRONG - InitialKeyboardIndicators is a string, not a DWORD
REG ADD "HKU\.DEFAULT\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_DWORD /d 2 /f
Output Concern:
The InitialKeyboardIndicators value is REG_SZ (a string). Writing it as REG_DWORD will cause Windows to ignore the setting entirely, and Num Lock will remain in its default off state.
The Wrong Way: Only Modifying HKCU
:: WRONG - Only affects the current user session, not the login screen
REG ADD "HKCU\Control Panel\Keyboard" /v InitialKeyboardIndicators /t REG_SZ /d "2" /f
This changes the Num Lock state for the current user after login but does not affect the Windows login screen or lock screen. To fix the login screen, you must target HKU\.DEFAULT.
Best Practices
- Target
HKU\.DEFAULT: This is the only hive that affects the Windows login screen. - Use the string type (
REG_SZ): Despite containing a number, this value must be written as a string. - Try
2147483650on modern Windows: The extended value is more reliable on Windows 10 and 11 than the classic2. - Check the BIOS: For complete coverage, enable the "Num Lock at Boot" option in the firmware alongside the registry change.
Conclusion
Setting Num Lock to ON at startup via Batch Script is a registry modification targeting the InitialKeyboardIndicators string value in the HKU\.DEFAULT\Control Panel\Keyboard key. By setting this value to 2 (or 2147483650 for modern Windows variants), administrators ensure that the numeric keypad is active from the moment the login screen appears. Extending the change to all loaded user profiles via SID enumeration guarantees a consistent experience across every account on the machine.