[SOLVED] Find BIOS Mode.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
PAB
Posts: 57
Joined: 12 Aug 2019 13:57

[SOLVED] Find BIOS Mode.

#1 Post by PAB » 04 Nov 2019 11:37

I have been trying to find what BIOS mode is being used.

For example, I just want it to show either . . .

UEFI with secure boot disabled
UEFI with secure boot enabled
LEGACY boot enabled

I have looked at doing this from bcdedit /enum.
I have tried reg query HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS.
. . . along with many others.

I just can't seem to extract the information needed!

Thanks in advance.
Last edited by PAB on 07 Nov 2019 09:35, edited 1 time in total.

aGerman
Expert
Posts: 3763
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find BIOS Mode.

#2 Post by aGerman » 04 Nov 2019 13:10

I don't see this information. Neither in the bcdedit output nor in the registry key. The only possibility I found is using a PowerShell cmdlet that you can call from within Batch.

Code: Select all

@echo off &setlocal
set "securemode="
set "biosmode="
for /f %%i in ('powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI"') do set "securemode=%%i"
if /i "%securemode%"=="False" (
  set "biosmode=UEFI with secure boot disabled" 
) else if /i "%securemode%"=="True" (
  set "biosmode=UEFI with secure boot enabled"
) else (
  powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI" | >nul find /i "PermissionDenied"
  if errorlevel 1 (
    set "biosmode=LEGACY boot enabled"
  ) else (
    echo Access denied. Run the script as Administrator!
    pause
    exit /b
  )
)

echo %biosmode%
pause
Not sure about the legacy mode though. I don't have access to a computer without UEFI.

Steffen

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: Find BIOS Mode.

#3 Post by PAB » 04 Nov 2019 15:58

That's brilliant Steffen.

I can confirm the code works on LEGACY mode.

So what would I use if I just needed to know if it was either UEFI or LEGACY please?

This produces LEGACY on my computer, does it produce UEFI on yours please?

Code: Select all

@echo off &setlocal
set "securemode="
set "biosmode="
for /f %%i in ('powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI"') do set "securemode=%%i"
if /i "%securemode%"=="False", "True" (
  set "biosmode=UEFI - GPT." 
) else (
  powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI" | >nul find /i "PermissionDenied"
  if errorlevel 1 (
    set "biosmode=LEGACY-MBR."
)
echo %biosmode%
pause
Thank you.

aGerman
Expert
Posts: 3763
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Find BIOS Mode.

#4 Post by aGerman » 05 Nov 2019 12:20

No, that's definitely not how IF works. There has to be only one comparison operand on each side of the comparison operator. Your script throws an error message that "True" is not recognized as an internal or external command (can't recall the exact English wording though).
Possible work-around

Code: Select all

@echo off &setlocal
set "biosmode=UEFI"
powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI" | >nul findstr /ib "True False" || (
  powershell.exe -nop -ep Bypass -c "Confirm-SecureBootUEFI" | >nul find /i "PermissionDenied"
  if errorlevel 1 (
    set "biosmode=LEGACY"
  ) else (
    echo Access denied. Run the script as Administrator!
    pause
    exit /b
  )
)

echo %biosmode%
pause
Steffen

PAB
Posts: 57
Joined: 12 Aug 2019 13:57

Re: [SOLVED] Find BIOS Mode.

#5 Post by PAB » 07 Nov 2019 09:39

Brilliant, thank you.

Post Reply