(view source code of bootstate.vbs as plain text)
Option Explicit
Dim arrSubKeys
Dim colItems, objItem, objReg, objWMIService
Dim strSubKey
Const HKEY_LOCAL_MACHINE = &H80000002
If WScript.Arguments.Count > 0 Then Syntax
On Error Resume Next
Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv" )
If objReg.EnumKey( HKEY_LOCAL_MACHINE, "SYSTEM\ControlSet001\Control", arrSubKeys ) = 0 Then
If Not Err And Not IsNull( arrSubKeys ) And Not IsEmpty( arrSubKeys ) Then
For Each strSubKey In arrSubKeys
If UCase( strSubKey ) = "MININT" Then
WScript.Echo "Windows PE"
Abort 3
End If
Next
End If
Else
Syntax
End If
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_ComputerSystem" )
If Not Err And Not IsNull( colItems ) And Not IsEmpty( colItems ) Then
For Each objItem in colItems
Select Case objItem.BootupState
Case "Normal boot":
WScript.Echo "Normal"
Abort 0
Case "Fail-safe boot":
WScript.Echo "Safe mode"
Abort 1
Case "Fail-safe with network boot" :
WScript.Echo "Safe mode with network"
Abort 2
End Select
Next
End If
On Error Goto 0
WScript.Echo "Unknown"
Abort -1
Sub Abort( intRC )
On Error Resume Next
Set objReg = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
On Error Goto 0
WScript.Quit intRC
End Sub
Sub Syntax( )
Dim strMsg
strMsg = "BootState.vbs, Version 1.00" _
& vbCrLf _
& "Show Windows' boot state" _
& vbCrLf & vbCrLf _
& "Usage: [ CSCRIPT.EXE //NoLogo ] BootState.vbs" _
& vbCrLf & vbCrLf _
& "Notes: Boot state is returned as string and as return code (""errorlevel""):" _
& vbCrLf _
& " ""Normal"" (return code = 0)" _
& vbCrLf _
& " ""Safe mode"" (return code = 1)" _
& vbCrLf _
& " ""Safe mode with network"" (return code = 2)" _
& vbCrLf _
& " ""Windows PE"" (return code = 3)" _
& vbCrLf _
& " In case of (command line) errors, the return code will be -1." _
& vbCrLf & vbCrLf _
& "Credits: Windows PE detection based on a tip by Mitch Tulloch" _
& vbCrLf _
& " http://techgenix.com/HowtodetectwhetheryouareinWindowsPE/" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" _
& vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
Abort -1
End Sub
page last modified: 2024-04-16; loaded in 0.0134 seconds