Jump to content

UEFI or BIOS Legacy boot (Win10 2004)


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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 :):)

Link to comment
Share on other sites

  • 3 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...