Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for numlock.bat

(view source code of numlock.bat as plain text)

  1. @ECHO OFF
  2. IF NOT [%2]==[] GOTO Syntax
  3. IF NOT [%OS%]==[Windows_NT] GOTO Syntax
  4.  
  5. REGEDIT /E "%Temp%.\numlock.dat" "HKEY_CURRENT_USER\Control Panel\Keyboard"
  6. FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\numlock.dat" ^| FIND /I "InitialKeyboardIndicators"') DO SET IKI=%%~A
  7.  
  8. IF [%1]==[]  GOTO :Read
  9. IF [%1]==[0] GOTO :Reset
  10. IF [%1]==[1] GOTO :Set
  11. GOTO Syntax
  12.  
  13. :Read
  14. SET /A IKI = "%IKI% & 2"
  15. IF %IKI%==2 (ECHO Default numlock state is ON) ELSE (ECHO Default numlock state is OFF)
  16. GOTO End
  17.  
  18. :Set
  19. SET /A IKI = "%IKI% | 2"
  20. GOTO :Store
  21.  
  22. :Reset
  23. SET /A IKI = "%IKI% & 253"
  24.  
  25. :Store
  26. >  "%Temp%.\numlock.dat" ECHO REGEDIT4
  27. >> "%Temp%.\numlock.dat" ECHO.
  28. >> "%Temp%.\numlock.dat" ECHO [HKEY_CURRENT_USER\Control Panel\Keyboard]
  29. >> "%Temp%.\numlock.dat" ECHO "InitialKeyboardIndicators"="%IKI%"
  30. >> "%Temp%.\numlock.dat" ECHO.
  31. REGEDIT.EXE /S "%Temp%.\numlock.dat"
  32.  
  33. :: Reread value from register
  34. REGEDIT /E "%Temp%.\numlock.dat" "HKEY_CURRENT_USER\Control Panel\Keyboard"
  35. FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\numlock.dat" ^| FIND /I "InitialKeyboardIndicators"') DO SET /A IKI = "%%~A & 2"
  36. IF %IKI%==2 (ECHO Default numlock state is now ON) ELSE (ECHO Default numlock state is now OFF)
  37. GOTO End
  38.  
  39. :Syntax
  40. ECHO.
  41. ECHO NumLock.bat,  Version 1.00 for Windows NT 4 / 2000 / XP
  42. ECHO Display or change the default NumLock status for the current user
  43. ECHO.
  44. ECHO Usage:  NUMLOCK  [ 0  1 ]
  45. ECHO.
  46. ECHO If no argument is specified, the current status will be displayed;
  47. ECHO 1 will turn the default NumLock status ON; 0 will turn it OFF.
  48. ECHO.
  49. ECHO Written by Rob van der Woude
  50. ECHO http://www.robvanderwoude.com
  51.  
  52. :End
  53. SET IKI=
  54. IF EXIST "%Temp%.\numlock.dat" DEL "%Temp%.\numlock.dat"
  55.  

page last uploaded: 2017-08-21, 14:26