************************************************
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 & " doesnt 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
