7,763
社区成员
发帖
与我相关
我的任务
分享
Public DL_R As String
Public DL_PN As String
Public DL_PD As String
Private Sub Get_PN(DL As String)
WQL = "Associators of {win32_LogicalDisk='" & DL & "'} where resultClass = Win32_DiskPartition"
Set Pattions = GetObject("winmgmts:").ExecQuery(WQL)
For Each Pat In Pattions
DL_PN = Pat.Name
DL_PD = Pat.DiskIndex
DL_R = CInt(DL_PD + 1) & ":" & CInt(Right(DL_PN, 1) + 1 + 1)
Next
End Sub
Private Sub Command1_Click()
Label1.Caption = DL_R
End Sub
Private Sub Drive1_Change()
Get_PN (Left(Drive1.Drive, 2))
Label1.Caption = DL_R
End Sub
Private Sub Form_Load()
Get_PN (Left(Drive1.Drive, 2))
Label1.Caption = DL_R
End Sub
Sub ListDrivesAndPartions()
Dim wmiServices, wmiDiskDrives, wmiDiskDrive
Dim strEscapedDeviceID, wmiDiskPartitions, wmiDiskPartition
Dim wmiLogicalDisks, wmiLogicalDisk
Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonate}!//.")
Set wmiDiskDrives = wmiServices.ExecQuery("SELECT Caption, DeviceID FROM Win32_DiskDrive")
For Each wmiDiskDrive In wmiDiskDrives
Debug.Print wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" _
& strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")
For Each wmiDiskPartition In wmiDiskPartitions
Debug.Print vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" _
& wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
Debug.Print vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
Next
End Sub
''
..