Enumerating Disk Drive Properties

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The Drives collection is typically used for inventory or monitoring purposes; as a system administrator, you need to know what drives are available on a computer, as well as details such as the drive serial number and the amount of free space on the drive. After you have returned a drives collection or an individual drive object, you can retrieve any of the properties shown in Table 4.2.

Table 4.2   Disk Drive Properties Available by Using the FileSystemObject

PropertyDescription
AvailableSpaceReports the amount of free space on the drive, in bytes. To report the amount of available space in kilobytes, divide this value by 1,024. To report the amount of available space in megabytes, divide this value by 1,048,576 (1,024 * 1,024).

The AvailableSpace property reports the amount of space available to the user running the script. If disk quotas are in use on the drive, this value might be less than the total amount of free space available on the drive.

DriveLetterDrive letter assigned to the drive. The drive letter does not include the trailing colon; thus, a floppy disk drive will be reported as A rather than A:.
DriveTypeInteger value indicating the type of drive. Values include:

1 Removable drive

2 Fixed drive (hard disk)

3 Mapped network drive

4 CD-ROM drive

5 RAM disk

FreeSpaceReports the amount of free space on the drive, in bytes. To report the amount of free space in kilobytes, divide this value by 1,024. To report the amount of free space in megabytes, divide this value by 1,048,576 (1,024 * 1,024).

Unlike the AvailableSpace property, FreeSpace reports the total amount of free space available on the drive, regardless of whether disk quotas have been enabled.

FileSystemType of file system used on the drive (FAT, FAT 32, NTFS).
IsReadyIndicates whether a drive is accessible. This value will be False for floppy disk drives or CD-ROM drives where no medium is inserted.
PathPath to the drive. For local drives, this will be the drive letter and the trailing colon (for example, A:). For mapped network drives, this will be the Universal Naming Convention (UNC) path for the drive (for example, \\Server1\SharedFolder).
RootFolderPath to the root folder on the drive.
SerialNumberSerial number assigned to the drive by the manufacturer. For floppy disk drives or mapped network drives, this value will typically be 0.
ShareNameShare name assigned to a mapped network drive.
TotalSizeReports the total size of the drive, in bytes. To report the total size in kilobytes, divide this value by 1,024. To report the total size in megabytes, divide this value by 1,048,576 (1,024 * 1,024).
VolumeNameVolume name (if any) assigned to the drive.

To enumerate the drives installed on a computer, create an instance of the FileSystemObject, create a reference to the Drives property, and then use a For Each loop to iterate through the set of drives. For each drive in the collection, you can echo any or all of the individual drive object properties shown in Table 4.2.

The script in Listing 4.3 echoes all the drive properties for every drive installed on a computer.

Listing 4.3   Enumerating Disk Drive Properties

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives For Each objDrive in colDrives     Wscript.Echo "Available space: " & objDrive.AvailableSpace     Wscript.Echo "Drive letter: " & objDrive.DriveLetter     Wscript.Echo "Drive type: " & objDrive.DriveType     Wscript.Echo "File system: " & objDrive.FileSystem     Wscript.Echo "Is ready: " & objDrive.IsReady     Wscript.Echo "Path: " & objDrive.Path     Wscript.Echo "Root folder: " & objDrive.RootFolder     Wscript.Echo "Serial number: " & objDrive.SerialNumber     Wscript.Echo "Share name: " & objDrive.ShareName     Wscript.Echo "Total size: " & objDrive.TotalSize     Wscript.Echo "Volume name: " & objDrive.VolumeName Next

When the script in Listing 4.3 runs under CScript, information similar to the following appears in the command window:

Available space: 10234975744 Drive letter: C Drive type: 2 File system: NTFS Free space: 10234975744 Is ready: True Path: C: Root folder: C:\ Serial number: 1343555846 Share name: Total size: 20398661632 Volume name: Hard Drive 

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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