abcd1258 发表于 2025-12-1 10:25:11

[求助]AU3如何判断磁盘是GPT还是MBR

#include <WinAPI.au3>
Global Const $ERROR_INVALID_FUNCTION = 0x1
DllCall("Kernel32.dll", "dword", "GetFirmwareEnvironmentVariableW", "wstr", "", "wstr", "{00000000-0000-0000-0000-000000000000}", "wstr", Null, "dword", 0)
If _WinAPI_GetLastError() = $ERROR_INVALID_FUNCTION Then
    MsgBox(0, '', 'Legacy BIOS - MBR')
Else
    MsgBox(0, '', 'UEFI - GPT')
EndIf
在网上找了这个,好像不起作用的。
大家有没有更加好的方法?

h111666b 发表于 2025-12-1 10:33:41

#include <Constants.au3>


If IsUEFI() Then
        MsgBox(4096, "", "UEFI")
Else
        MsgBox(4096, "", "传统")
EndIf

Func IsUEFI()
        Local $output = ""
        $output = Run(@ComSpec & " /c " & "bcdedit /enum | findstr /c:{fwbootmgr}", "", @SW_HIDE, $STDOUT_CHILD)
        $output = StringStripWS($output, 7)
        Return $output <> ""
EndFunc   ;==>IsUEFI
以前收藏的,看看能行不

abcd1258 发表于 2025-12-1 10:40:51

h111666b 发表于 2025-12-1 10:33
#include




不行哦,我的磁盘是传统模式,识别是UEFI 了。

chishingchan 发表于 2025-12-1 11:53:19

我也是用的是楼主这个,应该可以的。

chishingchan 发表于 2025-12-1 12:04:13

Global Const $error_invalid_function = 1

DllCall("Kernel32.dll", "dword", "GetFirmwareEnvironmentVariableW", "wstr", "", "wstr", "{00000000-0000-0000-0000-000000000000}", "wstr", Null, "dword", 0)

If _WinAPI_GetLastError() = $error_invalid_function Then
        $PartitionTable = "MBR"
Else
        $PartitionTable = "GPT"
EndIf

MsgBox(0,"磁盘分区表",$PartitionTable)

Func _WinAPI_GetLastError(Const $_icurrenterror = @error, Const $_icurrentextended = @extended)
        Local $aresult = DllCall("kernel32.dll", "dword", "GetLastError")
        Return SetError($_icurrenterror, $_icurrentextended, $aresult)
EndFunc

haijie1223 发表于 2025-12-1 14:00:46

这个代码是判断主板启动方式的,和磁盘没有关系。磁盘的话,需要读取磁盘分区表结构,记得论坛有代码,搜搜看。
页: [1]
查看完整版本: [求助]AU3如何判断磁盘是GPT还是MBR