Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bootstate.bat

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

  1. @ECHO OFF
  2. IF NOT "%~1"=="" GOTO Syntax
  3.  
  4. :: Check for WinPE
  5. REG.EXE Query HKLM\SYSTEM\ControlSet001\Control\MiniNT >NUL 2>&1
  6. IF NOT ERRORLEVEL 1 (
  7. 	ECHO Windows PE
  8. 	EXIT /B 3
  9. )
  10.  
  11. :: Check for "regular" boot state
  12. SETLOCAL ENABLEDELAYEDEXPANSION
  13. SET RC=-1
  14. FOR /F "tokens=*" %%A IN ('WMIC.EXE Path Win32_ComputerSystem Get BootupState ^| FIND.EXE " boot"') DO SET BootupState=%%A
  15. ECHO.%BootupState% | FIND.EXE "Normal boot" >NUL
  16. IF NOT ERRORLEVEL 1 (
  17. 	ECHO Normal
  18. 	SET RC=0
  19. )
  20. ECHO.%BootupState% | FIND.EXE "Fail-safe boot" >NUL
  21. IF NOT ERRORLEVEL 1 (
  22. 	ECHO Safe mode
  23. 	SET RC=1
  24. )
  25. ECHO.%BootupState% | FIND.EXE "Fail-safe with network boot" >NUL
  26. IF NOT ERRORLEVEL 1 (
  27. 	ECHO Safe mode with network
  28. 	SET RC=2
  29. )
  30. IF %RC% EQU -1 ECHO Unknown
  31. ENDLOCAL & EXIT /B %RC%
  32.  
  33.  
  34. :Syntax
  35. ECHO.
  36. ECHO BootState.bat,  Version 1.03
  37. ECHO Show Windows' boot state
  38. ECHO.
  39. ECHO Usage:    BootState.bat
  40. ECHO.
  41. ECHO Notes:    Boot state is returned as string and as "errorlevel" ^(return code^):
  42. ECHO               "Normal"                    ^(errorlevel = 0^)
  43. ECHO               "Safe mode"                 ^(errorlevel = 1^)
  44. ECHO               "Safe mode with network"    ^(errorlevel = 2^)
  45. ECHO               "Windows PE"                ^(errorlevel = 3^)
  46. ECHO           In case of ^(command line^) errors, the errorlevel will be -1.
  47. ECHO.
  48. ECHO Credits:  Windows PE detection based on a tip by Mitch Tulloch
  49. ECHO           http://techgenix.com/HowtodetectwhetheryouareinWindowsPE/
  50. ECHO.
  51. ECHO Written by Rob van der Woude
  52. ECHO http://www.robvanderwoude.com
  53. EXIT /B -1
  54.  

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