3月42018
获取磁盘信息
获取硬盘磁盘的
磁盘号 与 名称 和他分区
----------------------
#include <Array.au3>
Local $aDriveInfo, $iLastDevNumber = -1
Local $aFixed = DriveGetDrive('FIXED'), $aRemovable = DriveGetDrive('REMOVABLE')
Local $aDrives[ (IsArray($aFixed) ? $aFixed[0] : 0) + (IsArray($aRemovable) ? $aRemovable[0] : 0) ][3]
Local $iDrive = 0
For $i = 1 To UBound($aFixed) - 1
$aDrives[$iDrive][0] = $aFixed[$i]
$aDriveInfo = _WinAPI_GetDriveNumber($aFixed[$i])
If Not @error Then
$aDrives[$iDrive][1] = $aDriveInfo[1]
$aDrives[$iDrive][2] = $aDriveInfo[2]
EndIf
$iDrive += 1
Next
For $i = 1 To UBound($aRemovable) - 1
$aDrives[$iDrive][0] = $aRemovable[$i]
$aDriveInfo = _WinAPI_GetDriveNumber($aRemovable[$i])
If Not @error Then
$aDrives[$iDrive][1] = $aDriveInfo[1]
$aDrives[$iDrive][2] = $aDriveInfo[2]
EndIf
$iDrive += 1
Next
_ArraySort($aDrives, 0, 0, 0, 1)
Local $aDisks[ UBound($aDrives) ] [2]
Local $sDrivesInfo = "Drive list :" & @CRLF
Local $sOutput = ""
For $i = 0 To UBound($aDrives) - 1
If IsNumber($aDrives[$i][1]) Then
If $aDrives[$i][1] <> $iLastDevNumber Then
$iLastDevNumber = $aDrives[$i][1]
$aDisks[ $iLastDevNumber ][0] = "Disk " & $aDrives[$i][1] & " - " & _GetDiskNameByNumber($aDrives[$i][1]) & " - "
EndIf
$aDisks[ $iLastDevNumber ][1] &= $aDrives[$i][0] & ";"
EndIf
Next
Redim $aDisks[$iLastDevNumber + 1][2]
For $i = 0 To UBound($aDisks) - 1
$sOutput &= $aDisks[$i][0] & " ["
$aSplit = StringRegExp($aDisks[$i][1], "[^;]+", 3)
_ArraySort($aSplit)
For $j = 0 To UBound($aSplit) - 1
$sOutput &= $aSplit[$j] & "\, "
Next
$sOutput &= "]" & @CRLF
Next
$sOutput = StringReplace($sOutput, ", ]", "]")
MsgBox(0, "获取磁盘信息", $sOutput)
Func _GetDiskNameByNumber($iDiskNumber)
Local $iCount = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", "Count")
Local $sDiskKey = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\disk\Enum", String($iDiskNumber))
If @error Then Return SetError(1, 0, 0)
Local $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "FriendlyName")
If $sDiskName = "" Then $sDiskName = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $sDiskKey, "DeviceDesc")
Return $sDiskName
EndFunc```
<br />
<p>
</p>
<p>
------------------
</p>
<p>
</p>
<p>
</p>
<p>
</p>
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!