Identifying Drives and Drive Types
Microsoft® Windows® 2000 Scripting Guide
Enterprise scripting often involves configuring hardware and software on remote computers; in turn, this requires you to know, in advance, the type of disk drives installed on a computer. For example, a script that installs an application on drive E works only if drive E is a hard disk. If drive E happens to represent a floppy disk or a CD-ROM drive, the script fails.
Fortunately, you can use the Win32_LogicalDisk class to verify the drive type for each disk drive installed on a computer.
Listing 10.4 contains a script that identifies the drives and drive types installed on a computer. To carry out this task, the script must perform the following steps:
Create a variable to specify the computer name.
Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
Use the ExecQuery method to query the Win32_LogicalDisk class.
This query returns a collection consisting of all the logical disk drives (including hard disks, floppy disks, and compact discs) installed on the computer.
For each logical disk drive in the collection, echo the DeviceID (the drive letter) and the drive type.
The Win32_LogicalDisk class returns the value of the DriveType property as an integer. Therefore, a series of Select Case statements is used to convert the value to a text string. For example, if the DriveType is equal to 3, the string "Local hard disk" is echoed to the screen.
Listing 10.4 Identifying Drives and Drive Types
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24