虫子樱桃
发表于 2016-1-8 08:48:11
找了一段代码,应该可以的
#include <WinAPI.au3>
$_PARTITION_INFORMATION_MBR = 'byte PartitionType;' & _
'byte BootIndicator;' & _
'byte RecognizedPartition;' & _
'dword HiddenSectors;'
$_PARTITION_INFORMATION_GPT = 'byte TypeGuid;' & _
'byte IDGuid;' & _
'int64 Attributes;' & _
'wchar Name;'
$_PARTITION_INFORMATION_EX = 'int PartitionStyle;' & _
'int64 StartingOffset;' & _
'int64 PartitionLength;' & _
'dword PartitionNumber;' & _
'byte RewritePartition;' & _
'byte pad;' & _
$_PARTITION_INFORMATION_MBR & _
$_PARTITION_INFORMATION_GPT
$_PARTITION_INFORMATION_EX_2 = 'int PartitionStyle;' & _
'int64 StartingOffset;' & _
'int64 PartitionLength;' & _
'dword PartitionNumber;' & _
'byte RewritePartition;' & _
'byte pad;' & _
$_PARTITION_INFORMATION_GPT
$DRIVE_LAYOUT_INFORMATION_MBR = 'ULONG Signature;'
$DRIVE_LAYOUT_INFORMATION_GPT = 'byte Guid;' & _
'int64 StartingUsableOffset;' & _
'int64 UsableLength;' & _
'ulong MaxPartitionCount;'
$_DRIVE_LAYOUT = DllStructCreate('dword PartitionStyle;' & _
'dword PartitionCount;' & _
'byte union;' & _
'byte PartitionEntry')
$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')
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;'
For $x = 2 To $PartitionCount
$PartitionEntry &= 'byte;'
Next
$PartitionEntry &= 'byte'
$data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
$binaryStruct = DllStructCreate('byte')
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')
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;'
For $x = 2 To $PartitionCount
$PartitionEntry &= 'byte;'
Next
$PartitionEntry &= 'byte'
$data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry")
$binaryStruct = DllStructCreate('byte')
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/forum/topic/136907-need-help-with-ioctl_disk_get_drive_layout_ex/
yhjfirst
发表于 2016-1-8 11:34:11
https://msdn.microsoft.com/zh-cn/library/windows/desktop/aa364003(v=vs.85).aspx
DRIVE_LAYOUT_INFORMATION_GPT structure
Contains information about a drive's GUID partition table (GPT) partitions.
Syntax
C++
typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
GUID DiskId;
LARGE_INTEGER StartingUsableOffset;
LARGE_INTEGER UsableLength;
ULONG MaxPartitionCount;
} DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;
这参数不错,可惜不弄C++ ,虫子的出现总会带来惊喜{:face (356):}
skyfree
发表于 2016-1-8 15:41:34
回复 16# 虫子樱桃
非常感谢,我试一试。
haijie1223
发表于 2016-1-8 16:06:53
回复 16# 虫子樱桃
这段代码似乎和P版很像,而且好像没有P版的全面。
虫子樱桃
发表于 2016-1-8 16:43:41
回复 19# haijie1223
哈哈,没见过,找的老外写的
ddrs
发表于 2016-1-9 00:20:48
学下虫子大神的东西
haijie1223
发表于 2016-1-9 10:01:28
回复 20# 虫子樱桃
因为没有GPT的环境,虚拟机搭建了一个。好不容易整出GPT分区。用P版的代码,完全可以胜任。老外那个在P版的代码里都包含了,而且P版的更全面。MBR,GPT硬盘完全检测出。
haijie1223
发表于 2016-1-9 10:04:02
回复 18# skyfree
看看22楼,磁盘编号我自己加的,可能有点错误,应该是2:1,2:2,2:3
虫子樱桃
发表于 2016-1-9 14:45:56
回复 23# haijie1223
没代码啊,求代码
haijie1223
发表于 2016-1-9 15:19:57
搜一下,就是P版的代码。
haijie1223
发表于 2016-1-9 15:20:03
回复 24# 虫子樱桃
搜一下,就是P版的代码。
虫子樱桃
发表于 2016-1-10 19:14:12
回复 26# haijie1223
不晓得怎么搜,您就放个代码出来呗
haijie1223
发表于 2016-1-10 19:31:04
回复 27# 虫子樱桃
作为金牌会员,竟然说不会搜,先鄙视一下{:face (356):}
http://www.autoitx.com/forum.php?mod=viewthread&tid=13474&highlight=
kadingxiaodi
发表于 2016-1-11 15:30:24
学习一下{:face (411):}
anythinging
发表于 2016-1-12 22:59:28
非常感谢,我是新手,学习一下。