VBScript: 关联逻辑分区与物理磁盘

出处:http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/23/how-can-i-correlate-logical-drives-and-physical-disks.aspx

Code:

   1:  strComputer = "."
   2:  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   3:   
   4:  Set colDiskDrives = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
   5:  For Each objDrive In colDiskDrives
   6:      WScript.Echo "Physical Disk: " & objDrive.Caption & " -- " & objDrive.DeviceID
   7:      strDeviceID = Replace(objDrive.DeviceID, "\", "\\")
   8:      Set colPartitions = objWMIService.ExecQuery _
   9:          ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
  10:              strDeviceID & """} WHERE AssocClass = " & _
  11:                  "Win32_DiskDriveToDiskPartition")
  12:      For Each objPartition In colPartitions
  13:          WScript.Echo "Disk Partition: " & objPartition.DeviceID
  14:          Set colLogicalDisks = objWMIService.ExecQuery _
  15:          ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
  16:              objPartition.DeviceID & """} WHERE AssocClass = " & _
  17:                  "Win32_LogicalDiskToPartition")
  18:          For Each objLogicalDisk In colLogicalDisks
  19:              WScript.Echo "Logical Disk: " & objLogicalDisk.DeviceID
  20:          Next
  21:          WScript.Echo
  22:      Next
  23:      WScript.Echo
  24:  Next
posted @ 2013-02-27 10:34  ITGirl笑笑  阅读(383)  评论(0编辑  收藏  举报