window| hard Drive ' ************************************************
' File:GetDriveX.vbs (WSH sample in VBScript)
' Author: (c) G. Born
'
' Showing the properties of a drive by using
' FileSystemObject
'************************************************
Option Explicit
' Drive Type Constants
Const Unknown = 0
Const removable = 1 ' removable medium
Const fixed = 2 ' fixed medium (hard disk)
Const Remote = 3 ' network drive
Const CDROM = 4 ' CD-ROM
Const RAMDisk = 5 ' RAM disk
Dim Text, Title, drive
Dim FSO, odrive ' Object variable
Dim Drtype (6)
Drtype (0) = "Unknown"
Drtype (1) = "Removable"
Drtype (2) = "Fixed"
Drtype (3) = "Remote"
Drtype (4) = "CDROM"
Drtype (5) = "RAMDisk"
Text = "Drive" & VbCrLf & VbCrLf
Title = "WSH sample-by G. Born"
Drive = ""
Do ' Query drive letter.
Drive = InputBox ("drive letter (e.g. A)", "Drive", "C")
If drive = "" Then ' Test for Cancel button.
Wscript.Quit
End If
Drive = Left (drive, 1) ' Extract drive letter.
' Valid drive name (between A and Z)?
If ASC (UCase (drive)) < ASC ("A") Or _
ASC (UCase (drive)) > ASC ("Z") Then
MsgBox "Drive" & Drive & "is illegal"
Drive = ""
End If
Loop Until Drive <> ""
' Create FileSystemObject object to access the file system.
Set FSO = WScript.CreateObject ("Scripting.FileSystemObject")
' Check whether drive exists.
If (not FSO. Driveexists (drive)) Then
WScript.Echo "The Drive" & Drive & "doesn ' t exist"
Wscript.Quit
End If
Set odrive = fso. Getdrive (drive) ' Get drive object.
If (Odrive.isready) Then
Text = text & UCase (drive) & "-" & Odrive.volumename & VbCrLf
Text = text & "Drive type:" & Drtype (odrive.drivetype) & VbCrLf
Text = text & "File system:" & Odrive.filesystem & VbCrLf
Text = text + "Capacity:" & _
FormatNumber (odrive.totalsize/(1024*1024), 0) & _
"MB" & VbCrLf
Text = text & "Free:" & FormatNumber (odrive.freespace/1024, 0) _
& "KB" & VbCrLf
Else
Text = text & "Drive not Ready" & VbCrLf
End If
MsgBox Text, vbOKOnly + vbinformation, Title
' * * * end