WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: DirkM on June 05, 2014, 05:39:31 AM

Title: Translating Delphi code to Winbatch
Post by: DirkM on June 05, 2014, 05:39:31 AM
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
Title: Re: Translating Delphi code to Winbatch
Post by: td on June 05, 2014, 06:58:29 AM
Code (winbatch) Select
#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())
Title: Re: Translating Delphi code to Winbatch
Post by: DirkM on June 05, 2014, 07:42:37 AM
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
Title: Re: Translating Delphi code to Winbatch
Post by: Deana on June 05, 2014, 10:36:40 AM
Posted to tech database here: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/DllCall~Information+Booted~UEFI~or~BIOS.txt
Title: Re: Translating Delphi code to Winbatch
Post by: snowsnowsnow on June 05, 2014, 10:44:01 AM
Just out of curiosity, why does it matter which boot BIOS was used?

What's the underlying issue here?
Title: Re: Translating Delphi code to Winbatch
Post by: 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.
Title: Re: Translating Delphi code to Winbatch
Post by: snowsnowsnow on June 05, 2014, 12:28:00 PM
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.