新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim i As Integer
On Local Error Resume Next
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_DiskDrive")
For Each obj In wmiObjSet
Debug.Print "标题"; obj.Caption
Debug.Print "描述:"; obj.Description
Debug.Print "分区个数:"; obj.Partitions
Debug.Print "容量:"; obj.Size
i = i + 1
Next
Debug.Print "共有硬盘" & i & "块"
End Sub