Check whether a computer uses BIOS or UEFI

Windows specific forum
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Check whether a computer uses BIOS or UEFI

Post 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()
Last edited by Little John on Sun Sep 29, 2019 5:35 pm, edited 1 time in total.
User avatar
W4GNS
User
User
Posts: 31
Joined: Tue Jan 04, 2011 5:51 am
Location: Virginia

Re: Check whether a computer has BIOS or UEFI

Post by W4GNS »

Yes, returns true for me
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Check whether a computer has BIOS or UEFI

Post 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.
User avatar
idle
Always Here
Always Here
Posts: 5096
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Check whether a computer has BIOS or UEFI

Post by idle »

I get a zero on the ASRock 970 3 with win 10 x64
edit: apparently it's running in Legacy mode.
Windows 11, Manjaro, Raspberry Pi OS
Image
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: Check whether a computer has BIOS or UEFI

Post by Denis »

Returns #true for me

Win 10 - 64 bit (1809)

it matches with information given by msinfo32.exe
A+
Denis
juror
Enthusiast
Enthusiast
Posts: 228
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Check whether a computer has BIOS or UEFI

Post by juror »

correct for me - UEFI
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Check whether a computer has BIOS or UEFI

Post 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!
Post Reply