代码如下 原帖地址GetPartionMsg("", 1) ;GetPartionMsg 的第一个参数可以是 USB、IDE 等;如果不带任何参数,则是检测所有磁盘分区
;第二个参数可以是 1、0,1 表示 TRUE,0 表示 FALSE;如果第一个参数为空,则第二个必需为 1
Func GetPartionMsg($Interface, $b)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_LogicalDiskToPartition")
$DiskInfo = ""
$DiskInfoCombo = ""
For $objItem In $colItems
$DiskFH = StringLeft(StringRight($objItem.Dependent, 3), 2)
$PartNum = QueryDiskNum($DiskFH)
$PartMsg = QueryPartitionVolume($DiskFH)
If $Interface <> "" Then
If $b = 1 Then
If StringMid($PartNum, 2, 3) = $Interface Then
$DiskInfo = $DiskInfo & $PartNum & $DiskFH & $PartMsg & @CRLF
EndIf
ElseIf $b = 0 Then
If StringMid($PartNum, 2, 3) <> $Interface Then
$DiskInfo = $DiskInfo & $PartNum & $DiskFH & $PartMsg & @CRLF
EndIf
EndIf
Else
$DiskInfo = $DiskInfo & $PartNum & $DiskFH & $PartMsg & @CRLF
EndIf
Next
MsgBox(64, "磁盘信息", $DiskInfo)
EndFunc ;==>GetPartionMsg
Func QueryDiskInterface($n)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_DiskDrive Where Index=" & $n)
For $objItem In $colItems
Return $objItem.InterfaceType
Next
EndFunc ;==>QueryDiskInterface
Func QueryPartitionVolume($v)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Select * from Win32_LogicalDisk Where DeviceID='" & $v & "'")
For $objItem In $colItems
Return $objItem.VolumeName & "" & $objItem.FileSystem & "_" & CalcKMG($objItem.Size) & "_" & $objItem.Description
Next
EndFunc ;==>QueryPartitionVolume
Func QueryDiskNum($d)
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery ("Associators of {win32_LogicalDisk.DeviceID='" & $d & "'} where ResultClass = Win32_DiskPartition")
For $colItem In $colItems
Return "(" & QueryDiskInterface($colItem.DiskIndex) & ":hd" & $colItem.DiskIndex & ")"
Next
EndFunc ;==>QueryDiskNum
Func CalcKMG($n)
If $n < 1024 Then
Return $n & "Byte"
ElseIf $n < 1048576 Then
Return Round($n / 1024, 2) & "KB"
ElseIf $n < 1073741824 Then
Return Round($n / 1048576, 2) & "MB"
Else
Return Round($n / 1073741824, 2) & "GB"
EndIf
EndFunc ;==>CalcKMG
|