FreeBeing Posted June 13, 2020 Share Posted June 13, 2020 Hi, Since Windows 10 version 2004, DllCall with GetFirmwareEnvironmentVariable() or GetFirmwareEnvironmentVariableW() don't work anymore to detect UEFI or BIOS Legacy boot. To find another solution, I found GetFirmwareType() (for Windows 8 and 10, not 7) can do the job, but I don't have skill to use that correctly. I found PowerShell script that do the job with GetFirmwareType() : # Windows 8/Server 2012 or above: Function Get-BiosType { <# .Synopsis Determines underlying firmware (BIOS) type and returns an integer indicating UEFI, Legacy BIOS or Unknown. Supported on Windows 8/Server 2012 or later .DESCRIPTION This function uses a complied Win32 API call to determine the underlying system firmware type. .EXAMPLE If (Get-BiosType -eq 1) { # System is running BIOS firmware... } .EXAMPLE Switch (Get-BiosType) { 1 {"Legacy BIOS"} 2 {"UEFI"} Default {"Unknown"} } .OUTPUTS Integer indicating firmware type (1 = Legacy BIOS, 2 = UEFI, Other = Unknown) .FUNCTIONALITY Determines underlying system firmware type #> [OutputType([UInt32])] Param() Add-Type -Language CSharp -TypeDefinition @' using System; using System.Runtime.InteropServices; public class FirmwareType { [DllImport("kernel32.dll")] static extern bool GetFirmwareType(ref uint FirmwareType); public static uint GetFirmwareType() { uint firmwaretype = 0; if (GetFirmwareType(ref firmwaretype)) return firmwaretype; else return 0; // API call failed, just return 'unknown' } } '@ [FirmwareType]::GetFirmwareType() } # An electron is pulled-up for speeding. The policeman says, “Sir, do you realise you were travelling at 130mph?” The electron says, “Oh great, now I’m lost.” Get-BiosType I tried this PowerShell script, everything is OK (I obtain "1" with Legacy BIOS and "2" with UEFI). Please, anyone can help me to use GetFirmwareType() DllCall directly into AutoIt ? Thank you so much. i2i8 1 Link to comment Share on other sites More sharing options...
Earthshine Posted June 13, 2020 Share Posted June 13, 2020 (edited) Why not just use power shell Edited June 13, 2020 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Danyfirex Posted June 13, 2020 Share Posted June 13, 2020 Hello. Maybe This Global Enum $FirmwareTypeUnknown, _ $FirmwareTypeBios, _ $FirmwareTypeUefi, _ $FirmwareTypeMax ConsoleWrite("FirmwareType: " & _GetFirmwareType() & @CRLF) ConsoleWrite("FirmwareType: " & _GetFirmwareTypeString() & @CRLF) Func _GetFirmwareType() Local $aCall = DllCall("Kernel32.dll", "int", "GetFirmwareType", "int*", 0) If Not @error And $aCall[0] Then Return $aCall[1] Return SetError(1, 0, 0) EndFunc ;==>_GetFirmwareType Func _GetFirmwareTypeString() Local $iType = _GetFirmwareType() Local $asTypes[] = ["Unknown", "Bios", "Uefi", "Max"] Return $asTypes[$iType] EndFunc ;==>_GetFirmwareTypeString Saludos FreeBeing 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
FreeBeing Posted June 13, 2020 Author Share Posted June 13, 2020 3 hours ago, Earthshine said: Why not just use power shell Because I have a lot of AutoIt scripts that need this feature (I already use the old GetFirmwareEnvironmentVariable() function), and I don't want to mix AutoIt and Powershell if not really needed. Link to comment Share on other sites More sharing options...
FreeBeing Posted June 13, 2020 Author Share Posted June 13, 2020 2 hours ago, Danyfirex said: Hello. Maybe This Global Enum $FirmwareTypeUnknown, _ $FirmwareTypeBios, _ $FirmwareTypeUefi, _ $FirmwareTypeMax ConsoleWrite("FirmwareType: " & _GetFirmwareType() & @CRLF) ConsoleWrite("FirmwareType: " & _GetFirmwareTypeString() & @CRLF) Func _GetFirmwareType() Local $aCall = DllCall("Kernel32.dll", "int", "GetFirmwareType", "int*", 0) If Not @error And $aCall[0] Then Return $aCall[1] Return SetError(1, 0, 0) EndFunc ;==>_GetFirmwareType Func _GetFirmwareTypeString() Local $iType = _GetFirmwareType() Local $asTypes[] = ["Unknown", "Bios", "Uefi", "Max"] Return $asTypes[$iType] EndFunc ;==>_GetFirmwareTypeString Saludos Thanks god, your script is working Juste one thing, if it can help people for ConsoleWrite(), I quote AutoIt help : "The purpose for this function is to write to the STDOUT stream. Many popular text editors can read this stream. Scripts compiled as Console applications also have a STDOUT stream.This does not write to a DOS console unless the script is compiled as a console application." I tried your script into many Virtual Machines to be sure : - Windows 10 2004 x64 UEFI - Windows 10 2004 x64 BIOS - Windows 10 (older) x64 UEFI - Windows 10 (older) x64 BIOS - Windows 8.1 x64 UEFI - Windows 8.1 x64 BIOS - Windows 7 x64 BIOS As expected, everything is working except for Windows 7, so I will mix solutions : If Windows 7 --> the old GetFirmwareEnvironmentVariable() If Windows 8 or newer --> the "new" GetFirmwareType() Thanks a lot, again Danyfirex 1 Link to comment Share on other sites More sharing options...
drummerdp Posted August 20, 2023 Share Posted August 20, 2023 This function works properly and has been tested for all versions of Windows from XP to Win 11. It returns a string, either "UEFI" or "BIOS" _getfirmwaretype.au3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now