0

I want to know if the computer I'm using has UEFI or Legacy BIOS.

Is it somehow possible to detect this from Delphi code?

I found ExGetFirmwareEnvironmentVariable which seem interesting, but I'm not sure if it'll work or how to use it.

It would be nice to have something like this:

function IsUEFI: Boolean;
begin
 // Code to detect if it's UEFI or not.
end;
asked Dec 16, 2025 at 21:12
3
  • 1
    See this link: theroadtodelphi.com/2013/02/19/… Commented Dec 16, 2025 at 21:18
  • 1
    learn.microsoft.com/en-us/windows/win32/api/winbase/… is what you want, probably. Commented Dec 16, 2025 at 21:19
  • @dumbass That seems like it could work. So if I can wrap it somehow, then in theory I should be able to do something like Result := GetFirmwareType(FirmwareType) and (FirmwareType = FirmwareTypeUefi) to know whether it's UEFI or not? Commented Dec 16, 2025 at 21:26

2 Answers 2

0

From what I understand in the comment from @dumbass is that GetFirmwareType is the correct way to detect UEFI.

Therefore, I've gone ahead and wrote a standalone wrapper function for it like this:

function IsUEFI: Boolean;
type
 TFirmwareType = (
 FirmwareTypeUnknown,
 FirmwareTypeBios,
 FirmwareTypeUefi,
 FirmwareTypeMax
 );
 TGetFirmwareType = function(out FirmwareType: TFirmwareType): BOOL; stdcall;
begin
 Result := False;
 var Kernel: HMODULE := GetModuleHandle('kernel32.dll');
 if Kernel = 0 then
 Exit;
 var GetFirmwareType: TGetFirmwareType;
 @GetFirmwareType := GetProcAddress(Kernel, 'GetFirmwareType');
 if not Assigned(GetFirmwareType) then
 Exit;
 var FirmwareType: TFirmwareType;
 Result := GetFirmwareType(FirmwareType) and (FirmwareType = FirmwareTypeUefi);
end;

When I run:

if IsUEFI then
 Memo1.Lines.Add('Yes')
else
 Memo1.Lines.Add('No');

it does return "Yes" which is true for my computer. So I can only assume that it's working. I don't have a Legacy BIOS computer right now to test it on.

answered Dec 16, 2025 at 21:37
Sign up to request clarification or add additional context in comments.

Comments

0

I do also like what @Dave Nottage suggested.

Here's a standalone wrapper function for his method:

function IsUEFI: Boolean;
type
 TGetFirmwareEnvironmentVariableA = function(lpName: PAnsiChar; lpGuid: PAnsiChar; pBuffer: Pointer; nSize: DWORD): DWORD; stdcall;
begin
 Result := False;
 var Kernel: HMODULE := GetModuleHandle('kernel32.dll');
 if Kernel = 0 then
 Exit;
 var GetFirmwareEnvVar: TGetFirmwareEnvironmentVariableA;
 @GetFirmwareEnvVar := GetProcAddress(Kernel, 'GetFirmwareEnvironmentVariableA');
 if not Assigned(GetFirmwareEnvVar) then
 Exit;
 SetLastError(0);
 GetFirmwareEnvVar('', '{00000000-0000-0000-0000-000000000000}', nil, 0);
 Result := GetLastError <> ERROR_INVALID_FUNCTION;
end;

Again, when I run it like this:

if IsUEFI then
 Memo1.Lines.Add('Yes')
else
 Memo1.Lines.Add('No');

it does return "Yes" which is true for my computer. So I can only assume that it's working. I don't have a Legacy BIOS computer right now to test it on.

answered Dec 16, 2025 at 21:46

1 Comment

If you have any VM software installed like VM Ware you can easily check this in VM. Most VM environments that allow you to install full OS have ability to chose which BIOS type is to be simulated in VM.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.