找回密码
 加入
搜索
查看: 130|回复: 5

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

[复制链接]
发表于 2025-12-1 10:25:11 | 显示全部楼层 |阅读模式
#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
在网上找了这个,好像不起作用的。
大家有没有更加好的方法?

发表于 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
以前收藏的,看看能行不
 楼主| 发表于 2025-12-1 10:40:51 | 显示全部楼层

不行哦,我的磁盘是传统模式,识别是UEFI 了。
发表于 2025-12-1 11:53:19 | 显示全部楼层
我也是用的是楼主这个,应该可以的。
发表于 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[0])
EndFunc
发表于 2025-12-1 14:00:46 | 显示全部楼层
这个代码是判断主板启动方式的,和磁盘没有关系。磁盘的话,需要读取磁盘分区表结构,记得论坛有代码,搜搜看。

评分

参与人数 1威望 +2 金钱 +50 收起 理由
chishingchan + 2 + 50 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2025-12-10 06:55 , Processed in 0.065880 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表