Hello,
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/
{$APPTYPE CONSOLE}
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.
Thanks,
Dirk
#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())
Perfect, works like a charm, thanks a lot!
This might be something for the knowledge base since there is not much out there on the Internet on how to query the boot mode with WMI or vbscript, nor something that works on 32bit machines (since Windows 8.x now supports UEFI on 32bit hardware).
Thanks,
Dirk
Posted to tech database here: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/DllCall~Information+Booted~UEFI~or~BIOS.txt
Just out of curiosity, why does it matter which boot BIOS was used?
What's the underlying issue here?
In my automated image deployment I need to know if I need to deploy an efi partition (for UEFI) or not (for BIOS). There are also some software tools that need different versions/settings for UEFI based machines.
Quote from: DirkM on June 05, 2014, 12:05:45 PM
In my automated image deployment I need to know if I need to deploy an efi partition (for UEFI) or not (for BIOS). There are also some software tools that need different versions/settings for UEFI based machines.
Interesting. I didn't know that.