Recipe 7.1. Viewing the Disk, Drive, and Volume Layout


Problem

You want to see how the disks, drives, and volumes are laid out on a computer.

Solution

Using a graphical user interface

  1. Open the Computer Management snap-in.

  2. In the left pane, expand Storage and click on Disk Management. The right pane will display the disk, volumes, and drives.

Using a command-line interface

On Windows XP, you can use the diskpart utility to view the disk, drive, and volume configuration. First, get into interactive mode:

> diskpart

Next, to view the list of disks, run the following:

> list disk

Now, to see the list of volume and assigned drive letters, run the following:

> list vol

Using VBScript
' This code enumerates the physical and logical disks on a system. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." ' ------ END CONFIGURATION --------- WScript.Echo "Physical Disks:" set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDisks = objWMI.ExecQuery("select * from Win32_DiskDrive") for each objDisk in colDisks     WScript.Echo " Caption: " & vbTab &  objDisk.Caption     WScript.Echo " Device ID: " & vbTab &  objDisk.DeviceID     WScript.Echo " Manufacturer: " & vbTab & objDisk.Manufacturer     WScript.Echo " Media Type: " & vbTab &  objDisk.MediaType     WScript.Echo " Model: " & vbTab &  objDisk.Model     WScript.Echo " Name: " & vbTab &  objDisk.Name     WScript.Echo " Partitions: " & vbTab & objDisk.Partitions     WScript.Echo " Size: " & vbTab &  objDisk.Size          WScript.Echo " Status: " & vbTab &  objDisk.Status              WScript.Echo next WScript.Echo WScript.Echo "Logical Disks:" set colDisks = objWMI.ExecQuery("select * from Win32_LogicalDisk") for each objDisk in colDisks     WScript.Echo " DeviceID: " & objDisk.DeviceID           WScript.Echo " Description: " & objDisk.Description            WScript.Echo " VolumeName: " & objDisk.VolumeName       WScript.Echo " DriveType: " & objDisk.DriveType         WScript.Echo " FileSystem: " & objDisk.FileSystem       WScript.Echo " FreeSpace: " & objDisk.FreeSpace         WScript.Echo " MediaType: " & objDisk.MediaType         WScript.Echo " Name: " & objDisk.Name           WScript.Echo " Size: " & objDisk.Size           WScript.Echo next

Discussion

The solutions show how to enumerate all the disks and volumes on a computer, but if you have any mapped drives, it won't show those. The easiest way to see mapped drives is to open Windows Explorer and look at My Computer or run net use from a command line. From VBScript, you can use the Win32_MappedLogicalDisk WMI class, which is new to Windows XP. Here is some sample code:

strComputer = "." set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colDrives = objWMI.ExecQuery("select * from Win32_MappedLogicalDisk") WScript.Echo "Mapped Drives:" for each objDrive in colDrives     WScript.Echo " Device ID: " & objDrive.DeviceID     WScript.Echo " Volume Name: " & objDrive.VolumeName     WScript.Echo " Session ID: " & objDrive.SessionID     WScript.Echo " Size: " & objDrive.Size     WScript.Echo next

See Also

Recipe 7.12 for mapping a network drive



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net