meoit Posted December 12, 2016 Posted December 12, 2016 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. Asifmute 1
Terenz Posted December 12, 2016 Posted December 12, 2016 (edited) expandcollapse popupConsoleWrite(_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" EndSwitch 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" EndSwitch EndFunc ;==>_WinAPI_GetFirmwareEnvironmentVariable Edited December 12, 2016 by Terenz mlazovjp, Asifmute and meoit 3 Nothing is so strong as gentleness. Nothing is so gentle as real strength
mlazovjp Posted December 20, 2017 Posted December 20, 2017 On 12/12/2016 at 4:03 AM, Terenz said: expandcollapse popupConsoleWrite(_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" EndSwitch 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" EndSwitch EndFunc ;==>_WinAPI_GetFirmwareEnvironmentVariable Thank you for this. It has been difficult finding a reliable way to determine if Windows is running under UEFI or BIOS mode.
qhdpc Posted October 18, 2019 Posted October 18, 2019 DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDrive[0], _ "dword", 0x00070050, _ "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($tDriveLayout), _ "dword", DllStructGetSize($tDriveLayout), _ "dword*", 0, _ "ptr", 0) "0x00070050 " How to understand it here? Please explain it for me. Thank you.
Danyfirex Posted October 18, 2019 Posted October 18, 2019 Hello. @qhdpc It means this IOCTL_DISK_GET_DRIVE_LAYOUT_EX = 0x00070050 Saludos 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
ModemJunki Posted October 18, 2019 Posted October 18, 2019 (edited) On 12/20/2017 at 3:20 PM, mlazovjp said: Thank you for this. It has been difficult finding a reliable way to determine if Windows is running under UEFI or BIOS mode. While I would use the code Terenz wrote because it's technically much better than what I could do, I felt that I had to try a different way than what Terenz gave us, now we have a second way to determine UEFI or legacy. I had to try because I'm not familiar with creating DLL calls and I had not so much to do at work today. 🙂 Edited October 18, 2019 by ModemJunki Add info Always carry a towel.
qhdpc Posted October 20, 2019 Posted October 20, 2019 (edited) On 10/18/2019 at 4:56 PM, Danyfirex said: Hello. @qhdpc It means this IOCTL_DISK_GET_DRIVE_LAYOUT_EX = 0x00070050 Saludos Is 0x00070050 corresponding to IOCTL_DISK_GET_DRIVE_LAYOUT_EX ? Edited October 20, 2019 by qhdpc
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