本帖最后由 xdcysten 于 2010-1-17 03:34 编辑
上次提问了一个“DriveGetDrive怎样返回一组没有移动硬盘盘符的数组”,可惜最后还没有解决
例:假如本地有固定硬盘盘符4个分别为:C: D: E: F: 移动硬盘盘符这个有时候会发生一此变化有时是 H: 也可能是 I:
怎样可以像DriveGetDrive ( "类型" )那样使用_DriveGetDrive ( "REMOVABLE_DISK" ) 返回移动硬盘盘符数组
使用_DriveGetDrive ( "FIXED" ) 只 返回固定硬盘盘符数组不包含移动硬盘盘符的数组
如下:_DriveGetDrive ( "REMOVABLE_DISK" ) 返回像DriveGetDrive得到的数组 H:
_DriveGetDrive ( "FIXED" ) 返回像DriveGetDrive得到的数组 C: D: E: F:
_WinAPI_GetDriveBusType 可以返回以盘符 => 类型#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $Bus, $Text, $Drive = DriveGetDrive('FIXED')
For $i = 1 To $Drive[0]
$Bus = _WinAPI_GetDriveBusType($Drive[$i])
Switch $Bus
Case $DRIVE_BUS_TYPE_UNKNOWN
$Text = 'UNKNOWN'
Case $DRIVE_BUS_TYPE_SCSI
$Text = 'SCSI'
Case $DRIVE_BUS_TYPE_ATAPI
$Text = 'ATAPI'
Case $DRIVE_BUS_TYPE_ATA
$Text = 'ATA'
Case $DRIVE_BUS_TYPE_1394
$Text = '1394'
Case $DRIVE_BUS_TYPE_SSA
$Text = 'SSA'
Case $DRIVE_BUS_TYPE_FIBRE
$Text = 'FIBRE'
Case $DRIVE_BUS_TYPE_USB
$Text = 'USB'
Case $DRIVE_BUS_TYPE_RAID
$Text = 'RAID'
Case $DRIVE_BUS_TYPE_ISCSI
$Text = 'ISCSI'
Case $DRIVE_BUS_TYPE_SAS
$Text = 'SAS'
Case $DRIVE_BUS_TYPE_SATA
$Text = 'SATA'
Case $DRIVE_BUS_TYPE_SD
$Text = 'SD'
Case $DRIVE_BUS_TYPE_MMC
$Text = 'MMC'
EndSwitch
ConsoleWrite(StringUpper($Drive[$i]) & ' => ' & $Text & @CR)
Next
C: => ATA
D: => ATA
E: => ATA
F: => ATA
H: => USB
由于论坛下载附件的金钱有些过高,可能对于一个学习者是好的,因为您得回复帖子才有金钱去下载论坛附件,这也是一种美德。
但对于一个提问者来说就不是一件好事了,因为没有多少个人愿意去回复你的问题而还要浪费那30块 去下载你问题中的代码。
为了不浪费网友的金钱我提取了WinAPIEx.au3其中需要的代码出来如下:#Include-once
#Include <WinAPI.au3>
Global Const $DRIVE_BUS_TYPE_UNKNOWN = 0x00
Global Const $DRIVE_BUS_TYPE_SCSI = 0x01
Global Const $DRIVE_BUS_TYPE_ATAPI = 0x02
Global Const $DRIVE_BUS_TYPE_ATA = 0x03
Global Const $DRIVE_BUS_TYPE_1394 = 0x04
Global Const $DRIVE_BUS_TYPE_SSA = 0x05
Global Const $DRIVE_BUS_TYPE_FIBRE = 0x06
Global Const $DRIVE_BUS_TYPE_USB = 0x07
Global Const $DRIVE_BUS_TYPE_RAID = 0x08
Global Const $DRIVE_BUS_TYPE_ISCSI = 0x09
Global Const $DRIVE_BUS_TYPE_SAS = 0x0A
Global Const $DRIVE_BUS_TYPE_SATA = 0x0B
Global Const $DRIVE_BUS_TYPE_SD = 0x0C
Global Const $DRIVE_BUS_TYPE_MMC = 0x0D
Func _WinAPI_GetDriveBusType($sDrive)
Local $hFile = _WinAPI_CreateFile('\\.\' & $sDrive, 2, 0, 0)
If $hFile = 0 Then
Return SetError(1, 0, -1)
EndIf
Local $tSTORAGE_PROPERTY_QUERY = DllStructCreate('dword;dword;byte[4]')
Local $tSTORAGE_DEVICE_DESCRIPTOR = DllStructCreate('ulong;ulong;byte;byte;byte;byte;ulong;ulong;ulong;ulong;dword;ulong;byte[512]')
Local $Ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', 'ptr', $hFile, 'dword', 0x002D1400, 'ptr', DllStructGetPtr($tSTORAGE_PROPERTY_QUERY), 'dword', DllStructGetSize($tSTORAGE_PROPERTY_QUERY), 'ptr', DllStructGetPtr($tSTORAGE_DEVICE_DESCRIPTOR), 'dword', DllStructGetSize($tSTORAGE_DEVICE_DESCRIPTOR), 'dword*', 0, 'ptr', 0)
If (@error) Or ($Ret[0] = 0) Then
$Ret = 0
EndIf
_WinAPI_FreeHandle($hFile)
If Not IsArray($Ret) Then
Return SetError(2, 0, -1)
EndIf
Return SetError(0, 0, DllStructGetData($tSTORAGE_DEVICE_DESCRIPTOR, 11))
EndFunc ;==>_WinAPI_GetDriveBusType
Func _WinAPI_FreeHandle($hObject)
Local $Ret = DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $hObject)
If (@error) Or ($Ret[0] = 0) Then
Return SetError(1, 0, 0)
EndIf
Return 1
EndFunc ;==>_WinAPI_FreeHandle
|