WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DllCall Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Booted UEFI or BIOS

 Keywords: GetFirmwareEnvironmentVariableA GetFirmwareEnvironmentVariable Get Firmware Environment Variable Detect Windows System Machine Booted UEFI Legacy BIOS 

Question:

I'm looking for a way to detect if a machine was booted UEFI or legacy BIOS. I found this code that was written in Delphi and was wondering if there is a way to translate this into native Winbatch code: http://theroadtodelphi.wordpress.com/2013/02/19/how-distinguish-when-windows-was-installed-in-legacy-bios-or-uefi-mode-using-delphi/
 
uses
  Windows,
  SysUtils;
 
function GetFirmwareEnvironmentVariableA(lpName, lpGuid: LPCSTR; pBuffer: Pointer;
  nSize: DWORD): DWORD; stdcall; external kernel32 name 'GetFirmwareEnvironmentVariableA';
 
begin
  try
    GetFirmwareEnvironmentVariableA('','{00000000-0000-0000-0000-000000000000}', nil,0);
    if (GetLastError = ERROR_INVALID_FUNCTION) then
      Writeln('Legacy BIOS')
    else
      Writeln('UEFI Boot Mode');
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.
Any help would be appreciated.

Answer:

#DefineFunction GetFirmwareType()
   ERROR_INVALID_FUNCTION = 1
   DllCall("kernel32.dll",long:"GetFirmwareEnvironmentVariableA",lpstr:'',lpstr:'{00000000-0000-0000-0000-000000000000}', lpnull, long:0)
   If DllLastError() == ERROR_INVALID_FUNCTION  Then Return "Legacy BIOS"
   Else Return "UEFI Boot Mode"
#EndFunction

; Test
Message("Firmware", "System firmware: ": GetFirmwareType())

Article ID:   W18506
Filename:   Booted UEFI or BIOS.txt
File Created: 2014:06:05:10:35:42
Last Updated: 2014:06:05:10:35:42