Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for cmosbatt.bat

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

  1. @GOTO Run
  2.  
  3. o 70 0d
  4. i 71
  5.  
  6. q
  7.  
  8.  
  9. :Syntax
  10. ECHO.
  11. ECHO CMOSBatt.bat,  Version 1.00 for Windows NT 4 and later
  12. ECHO Check the CMOS battery status
  13. ECHO.
  14. ECHO Usage:    CMOSBATT
  15. ECHO.
  16. ECHO Returns:  On screen text: CMOS battery OK or NOT OK
  17. ECHO           Return code (errorlevel) 0 = OK, 1 = NOT OK
  18. ECHO.
  19. ECHO Written by Rob van der Woude
  20. ECHO http://www.robvanderwoude.com
  21. GOTO :End
  22.  
  23.  
  24. :Run
  25. @ECHO OFF
  26. :: Check Windows version
  27. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  28. :: Check command line (no arguments required)
  29. IF NOT "%~1"=="" GOTO Syntax
  30. :: Localize variables
  31. SETLOCAL
  32. :: Read bit 7 of CMOS register 13
  33. FOR /F "skip=1" %%A IN ('DEBUG ^< "%~sf0" ^| FIND /V "-"') DO SET /A Status = "( 0x%%~A >> 7 ) %% 2"
  34. :: Invert the result
  35. SET /A Status = 1 - %Status%
  36. :: Display the result on screen and set returncode
  37. IF %Status% EQU 0 (
  38. 	ECHO CMOS battery OK
  39. 	ENDLOCAL
  40. ) ELSE (
  41. 	ECHO CMOS battery NOT OK
  42. 	ENDLOCAL
  43. 	COLOR FF
  44. )
  45. :End
  46.  

page last modified: 2024-02-26; loaded in 0.0151 seconds