Page 1 of 1

Check whether a computer uses BIOS or UEFI

Posted: Fri Sep 27, 2019 10:36 pm
by Little John
Hi all,

the following code returns #False on my PC with BIOS, as expected.

I would appreciate it, if some of you would test the code on your systems.
Especially interesting for me is to know, whether the function actually returns #True on computers with UEFI.
I'd also be grateful for suggestions for improvement, if necessary.
Thanks in advance!

Code: Select all

EnableExplicit

Import "kernel32.lib"
   GetFirmwareEnvironmentVariableA (name.p-ascii, guid.p-ascii, *buffer, nSize.l)
EndImport


Procedure.i UsesUEFI()
   ; out: #True  if the used system firmware is UEFI,
   ;      #False if the used system firmware is BIOS.
   ;
   ; <https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getfirmwareenvironmentvariablea>, 2019-09-24
   ; tested with PB 5.71 (x86 and x64) under Windows 10 Pro Version 1903 with BIOS
   Protected *buffer, error.i, nSize.l=1000
   
   *buffer = AllocateMemory(nSize)
   GetFirmwareEnvironmentVariableA("", "{00000000-0000-0000-0000-000000000000}", *buffer, nSize)
   error = GetLastError_()
   FreeMemory(*buffer)
   
   ProcedureReturn Bool(error <> #ERROR_INVALID_FUNCTION)
EndProcedure


;-- Demo
Debug UsesUEFI()

Re: Check whether a computer has BIOS or UEFI

Posted: Fri Sep 27, 2019 11:17 pm
by W4GNS
Yes, returns true for me

Re: Check whether a computer has BIOS or UEFI

Posted: Sat Sep 28, 2019 2:29 am
by BarryG
Mine returns 1 (UEFI), as confirmed with the Windows "System Information" app.

Your code matches the CPP source posted by Martin Karer here:

https://social.technet.microsoft.com/Fo ... de-windows

So I'd say it's correct.

Re: Check whether a computer has BIOS or UEFI

Posted: Sat Sep 28, 2019 6:59 am
by idle
I get a zero on the ASRock 970 3 with win 10 x64
edit: apparently it's running in Legacy mode.

Re: Check whether a computer has BIOS or UEFI

Posted: Sat Sep 28, 2019 8:50 am
by Denis
Returns #true for me

Win 10 - 64 bit (1809)

it matches with information given by msinfo32.exe

Re: Check whether a computer has BIOS or UEFI

Posted: Sat Sep 28, 2019 5:55 pm
by juror
correct for me - UEFI

Re: Check whether a computer has BIOS or UEFI

Posted: Sun Sep 29, 2019 5:31 pm
by Little John
Many thanks for all your replies! They are much appreciated.
idle wrote:I get a zero on the ASRock 970 3 with win 10 x64
edit: apparently it's running in Legacy mode.
Yes, even a modern PC with an UEFI can run in Legacy mode.
The old function name was misleading. I changed it to UsesUEFI(), and also changed the thread title accordingly.

Many thanks again, and especially to BarryG for the link!

Re: Check whether a computer uses BIOS or UEFI

Posted: Sat Jun 08, 2024 3:01 pm
by hoangdiemtinh
Not working.

my PC: Win10 Pro 64-bit, run on a MBR System Disk (this is Legacy Windows Environment).

(my MainBoard have support EFI Booting in BIOS Setup).

But, this code return #True.

Please fix code.

Re: Check whether a computer uses BIOS or UEFI

Posted: Thu Jun 27, 2024 10:20 am
by Zero Ray
hoangdiemtinh wrote: Sat Jun 08, 2024 3:01 pm Not working.

my PC: Win10 Pro 64-bit, run on a MBR System Disk (this is Legacy Windows Environment).

(my MainBoard have support EFI Booting in BIOS Setup).

But, this code return #True.

Please fix code.
Try it

Code: Select all

#SystemBootEnvironmentInformation = $5A

Structure _SYSTEM_BOOT_ENVIRONMENT_INFORMATION Align #PB_Structure_AlignC
  BootIdentifier.guid
  FirmwareType.l
  BootFlags.d
EndStructure

Procedure GetSystemBootEnvironmentInformation()
  Protected SBEI._SYSTEM_BOOT_ENVIRONMENT_INFORMATION
  
  If NtQuerySystemInformation_(#SystemBootEnvironmentInformation, @SBEI, SizeOf(SBEI), #Null) = 0
    ProcedureReturn SBEI\FirmwareType
  Else
    ProcedureReturn -1
  EndIf
EndProcedure

Select GetSystemBootEnvironmentInformation()
  Case 0
    Debug "Unknown"
  Case 1
    Debug "Bios"
  Case 2
    Debug "Uefi"
  Case 3
    Debug "Not implemented"
  Case -1
    Debug "Error"
EndSelect

Re: Check whether a computer uses BIOS or UEFI

Posted: Thu Jun 27, 2024 11:47 am
by Little John

Re: Check whether a computer uses BIOS or UEFI

Posted: Thu Jun 27, 2024 12:27 pm
by Zero Ray
Little John wrote: Thu Jun 27, 2024 11:47 am See also this forum contribution.
The GetFirmwareType function is only available in version NT6.2 and higher