有没有能够获取磁盘名称以及其他扩展信息的API方法或是思路?
DiskPartitionsCylindersHeadsSectorsMbytesModel1 3 121601 255 63953869.8ST1000DM 003-1SB102 CC63
上面是GDisk的输出结果,请教各位大神如何用纯AU3获得,不使用WMI(某些pe不能用) 读取扇区信息,或者用磁盘相关api,据我所知,有好几种方法。 api DeviceIoControl afan 发表于 2020-3-30 23:19
api DeviceIoControl
可否给个调用示例,文档看不懂:face (13): haijie1223 发表于 2020-3-30 21:06
读取扇区信息,或者用磁盘相关api,据我所知,有好几种方法。
大佬讲讲 afan 发表于 2020-3-30 23:19
api DeviceIoControl
#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
上面这段代码执行后无效果 ;获取硬盘信息(序列号SerialNumber、序号DeviceID、品牌型号Model,其它信息可以搜索Win32_diskdrive获取相关命令)
Local $Win32_diskdrive = Run(@SystemDir & '\WindowsPowerShell\v1.0\powershell.exe Get-WmiObject -Class Win32_diskdrive SerialNumber,DeviceID,Model', '', @SW_HIDE, $STDERR_MERGED)
ProcessWaitClose($Win32_diskdrive, 5)
Local $etxt = StdoutRead($Win32_diskdrive)
MsgBox($MB_SYSTEMMODAL, '', $etxt) itsky2 发表于 2020-3-31 22:17
#include
$_PARTITION_INFORMATION_MBR = 'byte PartitionType;' & _
.PhysicalDrive0改为 \\.\PhysicalDrive0 fybhwsx 发表于 2020-4-5 13:16
谢谢大佬哈,不用WMI的 afan 发表于 2020-4-5 13:28
.PhysicalDrive0改为 \\.\PhysicalDrive0
成功运行,非常感谢!
还是不知道磁盘名怎么获取..:face (32): https://www.autoitx.com/forum.php?mod=viewthread&tid=9507&highlight=%B4%BFAU
P版的代码能帮到你吧,不过在我这儿运行不了?
提示:
"Z:\GetDiskSerialNumber.au3"(4,80) : 错误: $IOCTL_STORAGE_QUERY_PROPERTY 先前声明为 'Const' 常量.
Const $IOCTL_STORAGE_QUERY_PROPERTY = _MakeCtrlCode($IOCTL_STORAGE_BASE, 0x500)
页:
[1]