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 first, as WMI might not be available in 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. WMIC.EXE Path Win32_ComputerSystem Get BootupState | FIND.EXE "Normal boot" >NUL
  13. IF NOT ERRORLEVEL 1 (
  14. 	ECHO Normal
  15. 	EXIT /B 0
  16. )
  17.  
  18. WMIC.EXE Path Win32_ComputerSystem Get BootupState | FIND.EXE "Fail-safe boot" >NUL
  19. IF NOT ERRORLEVEL 1 (
  20. 	ECHO Safe mode
  21. 	EXIT /B 1
  22. )
  23.  
  24. WMIC.EXE Path Win32_ComputerSystem Get BootupState | FIND.EXE "Fail-safe with network boot" >NUL
  25. IF NOT ERRORLEVEL 1 (
  26. 	ECHO Safe mode with network
  27. 	EXIT /B 2
  28. )
  29.  
  30. ECHO Unknown
  31. EXIT /B -1
  32.  
  33.  
  34. :Syntax
  35. ECHO.
  36. ECHO BootState.bat,  Version 1.04
  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 modified: 2024-04-16; loaded in 0.0085 seconds