Detect an UEFI Windows and GPT Disk type

2 posts in this topic

Hello all !

Sorry for my bad English.

I am trying to create an application and I need get UEFI Windows type and GPT Disk type.

I searched a lot on Google but did not find.

Someone help me.

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

ConsoleWrite(_GetDrivePartitionStyle() & @CRLF)
ConsoleWrite(_WinAPI_GetFirmwareEnvironmentVariable() & @CRLF)

Func _GetDrivePartitionStyle($sDrive = "C")
    Local $tDriveLayout = DllStructCreate('dword PartitionStyle;' & _
            'dword PartitionCount;' & _
            'byte union[40];' & _
            'byte PartitionEntry[8192]')
    Local $hDrive = DllCall("kernel32.dll", "handle", "CreateFileW", _
            "wstr", "\\.\" & $sDrive & ":", _
            "dword", 0, _
            "dword", 0, _
            "ptr", 0, _
            "dword", 3, _ ; OPEN_EXISTING
            "dword", 0, _
            "ptr", 0)
    If @error Or $hDrive[0] = Ptr(-1) Then Return SetError(@error, @extended, 0) ; INVALID_HANDLE_VALUE
    DllCall("kernel32.dll", "int", "DeviceIoControl", _
            "hwnd", $hDrive[0], _
            "dword", 0x00070050, _
            "ptr", 0, _
            "dword", 0, _
            "ptr", DllStructGetPtr($tDriveLayout), _
            "dword", DllStructGetSize($tDriveLayout), _
            "dword*", 0, _
            "ptr", 0)
    DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hDrive[0])
    Switch DllStructGetData($tDriveLayout, "PartitionStyle")
        Case 0
            Return "MBR"
        Case 1
            Return "GPT"
        Case 2
            Return "RAW"
        Case Else
            Return "UNKNOWN"
EndFunc   ;==>_GetDrivePartitionStyle

Func _WinAPI_GetFirmwareEnvironmentVariable()
    DllCall("kernel32.dll", "dword", _
            "GetFirmwareEnvironmentVariableW", "wstr", "", _
            "wstr", "{00000000-0000-0000-0000-000000000000}", "wstr", "", "dword", 4096)
    Local $iError = DllCall("kernel32.dll", "dword", "GetLastError")
    Switch $iError[0]
        Case 1
            Return "LEGACY"
        Case 998
            Return "UEFI"
        Case Else
            Return "UNKNOWN"
EndFunc   ;==>_WinAPI_GetFirmwareEnvironmentVariable


Edited by Terenz
1 person likes this

Nothing is so strong as gentleness. Nothing is so gentle as real strength


Share this post

Link to post
Share on other sites

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