找了一段代码,应该可以的
#include <WinAPI.au3>
$_PARTITION_INFORMATION_MBR = 'byte PartitionType;' & _
'byte BootIndicator;' & _
'byte RecognizedPartition;' & _
'dword HiddenSectors;'
$_PARTITION_INFORMATION_GPT = 'byte TypeGuid[16];' & _
'byte IDGuid[16];' & _
'int64 Attributes;' & _
'wchar Name[36];'
$_PARTITION_INFORMATION_EX = 'int PartitionStyle;' & _
'int64 StartingOffset;' & _
'int64 PartitionLength;' & _
'dword PartitionNumber;' & _
'byte RewritePartition;' & _
'byte pad[3];' & _
$_PARTITION_INFORMATION_MBR & _
$_PARTITION_INFORMATION_GPT
$_PARTITION_INFORMATION_EX_2 = 'int PartitionStyle;' & _
'int64 StartingOffset;' & _
'int64 PartitionLength;' & _
'dword PartitionNumber;' & _
'byte RewritePartition;' & _
'byte pad[3];' & _
$_PARTITION_INFORMATION_GPT
$DRIVE_LAYOUT_INFORMATION_MBR = 'ULONG Signature;'
$DRIVE_LAYOUT_INFORMATION_GPT = 'byte Guid[16];' & _
'int64 StartingUsableOffset;' & _
'int64 UsableLength;' & _
'ulong MaxPartitionCount;'
$_DRIVE_LAYOUT = DllStructCreate('dword PartitionStyle;' & _
'dword PartitionCount;' & _
'byte union[40];' & _
'byte PartitionEntry[8192]')
$hDrive = _WinAPI_CreateFile('.PHYSICALDRIVE0', 2, 0)
Local $Ret = DllCall("kernel32.dll", "int", "DeviceIoControl", _
"hwnd", $hDrive, _
"dword", 0x00070050, _
"ptr", 0, _
"dword", 0, _
"ptr", DllStructGetPtr($_DRIVE_LAYOUT), _
"dword", DllStructGetSize($_DRIVE_LAYOUT), _
"dword*", 0, _
"ptr", 0)
Switch DllStructGetData($_DRIVE_LAYOUT, "PartitionStyle")
Case 0 ;MBR
$data = DllStructGetData($_DRIVE_LAYOUT, "union")
$binaryStruct = DllStructCreate('byte[8192]')
DllStructSetData($binaryStruct, 1, $data)
$DriveMBRInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_MBR, DllStructGetPtr($binaryStruct))
ConsoleWrite('MBR Signature: ' & Hex(DllStructGetData($DriveMBRInfo, "Signature"), 8) & @CRLF & @CRLF)
$PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount")
$PartitionEntry = 'byte[144];'
For $x = 2 To $PartitionCount
$PartitionEntry &= 'byte[144];'
Next
$PartitionEntry &= 'byte[8192]'
$data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
$binaryStruct = DllStructCreate('byte[8192]')
DllStructSetData($binaryStruct, 1, $data)
$PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct))
For $x = 1 To $PartitionCount
$Partion = DllStructCreate($_PARTITION_INFORMATION_EX, DllStructGetPtr($PartitionEntry, $x))
If Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop
ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF)
ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF)
ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF)
ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion, 'PartitionLength') & @CRLF)
ConsoleWrite('RecognizedPartition: ' & DllStructGetData($Partion, 'RecognizedPartition') & @CRLF)
ConsoleWrite('PartitionType: ' & DllStructGetData($Partion, 'PartitionType') & @CRLF)
ConsoleWrite('BootIndicator: ' & DllStructGetData($Partion, 'BootIndicator') & @CRLF)
ConsoleWrite('HiddenSectors: ' & DllStructGetData($Partion, 'HiddenSectors') & @CRLF & @CRLF)
Next
Case 1 ;GPT
;GPT stuff here ...
$data = DllStructGetData($_DRIVE_LAYOUT, "union")
$binaryStruct = DllStructCreate('byte[8192]')
DllStructSetData($binaryStruct, 1, $data)
$DriveGPTInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_GPT, DllStructGetPtr($binaryStruct))
ConsoleWrite('Guid: ' & _BeautyGUID(DllStructGetData($DriveGPTInfo, "Guid")) & @CRLF & @CRLF)
ConsoleWrite('StartingUsableOffset: ' & Int(DllStructGetData($DriveGPTInfo, "StartingUsableOffset")) & @CRLF)
ConsoleWrite('UsableLength: ' & Int(DllStructGetData($DriveGPTInfo, "UsableLength")) & @CRLF)
ConsoleWrite('MaxPartitionCount: ' & Int(DllStructGetData($DriveGPTInfo, "MaxPartitionCount")) & @CRLF & @CRLF)
$PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount")
$PartitionEntry = 'byte[144];'
For $x = 2 To $PartitionCount
$PartitionEntry &= 'byte[144];'
Next
$PartitionEntry &= 'byte[8192]'
$data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
$binaryStruct = DllStructCreate('byte[8192]')
DllStructSetData($binaryStruct, 1, $data)
$PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct))
For $x = 1 To $PartitionCount
$Partion = DllStructCreate($_PARTITION_INFORMATION_EX_2, DllStructGetPtr($PartitionEntry, $x))
If Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop
ConsoleWrite('Name: ' & DllStructGetData($Partion, 'Name') & @CRLF)
ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF)
ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF)
ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF)
ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion, 'PartitionLength') & @CRLF)
ConsoleWrite('TypeGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'TypeGuid')) & @CRLF)
ConsoleWrite('IDGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'IDGuid')) & @CRLF)
ConsoleWrite('Attributes: ' & Int(DllStructGetData($Partion, 'Attributes')) & @CRLF & @CRLF)
Next
Case 2 ; RAW
ConsoleWrite('RAW Disk - no information available' & @CRLF)
EndSwitch
Func _BeautyGUID($GUID)
$GUID = StringLower($GUID)
If StringLeft($GUID, 2) = '0x' Then $GUID = StringTrimLeft($GUID, 2)
Return '{' & StringLeft($GUID, 8) & '-' & StringMid($GUID, 9, 4) & '-' & StringMid($GUID, 13, 4) & '-' & StringMid($GUID, 17, 4) & '-' & StringRight($GUID, 8) & '}'
EndFunc ;==>_BeautyGUID
原帖地址 https://www.autoitscript.com/for ... et_drive_layout_ex/ |