|
ASP Kitchen: ASPWatch.com
articles: VBScript Drives Collection
Using the VBScript Drives Collection
Introduction
This article demonstrates how to access information about disk drives attached to a web
server supporting ASP.
The techniques described here could have many uses, such as:
- Making sure a server supporting uploading of files has sufficient disk space available
before large files are uploaded.
- Creating an ASP document that will allow remote monitoring of disk space while the
server administrator is out of town.
Starting out
The version of VBScript supplied with Internet Information Server (IIS) version 4.0 and
above is supplied with several objects that are able to interact with and extract
information from the machine's filesystem. Although the FileSystemObject object is
commonly used to read and write text files from ASP documents, it has other uses, as will
be demonstrated here...
The following script demonstrates the VBScript Drives Collection:
<%
'Script to display a list of drives connected to this machine
Set FileSystemObject = Server.CreateObject("Scripting.FileSystemObject") 'Create
a filesystem object
Set Drives = FileSystemObject.Drives 'Create a drives collection
'step through the drive collection, and extract
'the drive letter and the type of drive
'according to the Microsoft VBScript documentation
'there are 6 distinct types of drive
For Each DiskDrive in Drives
DriveLetter = DiskDrive.DriveLetter
DriveType = DiskDrive.DriveType
Select Case DriveType
Case "0" DriveType = "Unknown type of drive"
Case "1" DriveType = "Removable drive"
Case "2" DriveType = "Fixed drive"
Case "3" DriveType = "Network drive"
Case "4" DriveType = "CD-ROM drive"
Case "5" DriveType = "RAM Disk"
End Select
Response.Write "Drive " & DriveLetter & " is a " &
DriveType & "<BR>"
Next
Set Drives = nothing
Set FileSystemObject = nothing
%>
If you run this script, it should report the status of the drives attached to your
system, e.g.

In this example, the A drive has been identified as a removable drive (it's the floppy
disk), drive E is also removable (a ZIP disk), drive G is the CD-ROM, and the rest are
fixed drives (i.e. hard disks) with the exception of drive J, which is mapped to a network
drive.
Further drive properties
As can be seen from the code sample above, two properties of the Drives collection are
accessed: DriveLetter and DriveType. There are a total of 12 properties that can be
obtained about a specific drive:
- AvailableSpace: space left on the drive (in bytes)
- DriveLetter: the drive's letter
- DriveType: the type of drive (e.g. CD-ROM, network drive etc.)
- FileSystem: the type of file system used on the specificed drive (e.g. NTFS, FAT)
- FreeSpace: space left on the drive available to the current user (in bytes)
- IsReady: indicates whether the drive can be accessed
- Path: the path to the specified drive
- RootFolder: returns a folder object for the given drive
- SerialNumber: the unique number for the specified drive
- ShareName: the network share name for the drive (if it has one)
- TotalSize: the total amount of storage space on the drive
- VolumeName: the name of the drive
Many of the properties (e.g. AvailableSpace, FileSystem) can only be accessed by
VBScript directly checking the drive in question. This will cause script errors if there
is an attempt to check a drive that is not available (e.g. the floppy disk drive is
empty).
Fortunately it is possible to check to see if a drive is ready by using the drive's
IsReady property:
<%
'Script to display a list of drives connected to this machine
and also to check if a disk drive is ready
Set FileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
Set Drives = FileSystemObject.Drives
For Each DiskDrive in Drives
DriveLetter = DiskDrive.DriveLetter
DriveType = DiskDrive.DriveType
Select Case DriveType
Case "0" DriveType = "Unknown type of drive"
Case "1" DriveType = "Removable drive"
Case "2" DriveType = "Fixed drive"
Case "3" DriveType = "Network drive"
Case "4" DriveType = "CD-ROM drive"
Case "5" DriveType = "RAM Disk"
End Select
Response.Write "Drive " & DriveLetter & " is a " &
DriveType & " "
'If the drive is ready, display a blue piece of text.
'If the drive is not ready, display a red piece of text.
If DiskDrive.IsReady then
Response.Write "<FONT COLOR=#0000FF>This drive is ready for
use</FONT>"
Else
Response.Write "<FONT COLOR=#FF0000>This drive is not ready for
use</FONT>"
End If
Response.Write "<BR>"
Next
Set Drives = nothing
Set FileSystemObject = nothing
%>
This script can be easily tested by putting in or removing a floppy disk or CD-ROM from
the disk drive. This will toggle the display for the A drive, as shown below:

Script enhancements
A further enhancement of the scripts shown here would be to show a graphical
representation of the various drive types. In another article, the scripts shown here are used
as a basis of a graphical ASP drive space indicator.
Don't forget as well that this code could also be used as the basis of a Windows
Scripting Host script to continuously monitor disk resource usage.
Finally, always ensure that you know exactly who is able to view such information about
your system. The less information you reveal to the whole Internet community, the better.
Further reading
Useful Development Tools
| ASP
Documentation Tool |
| Automatically creates technical documentation for ASP 2.0
and 3.0 web applications written in VBScript and JScript. Documentation for Microsoft
Access, SQL Server 7/2000 databases and Visual Basic 6.0 components associated with the
web application can also be incorporated into the reports. Documentation is created in
HTML, HTML Help and plain text formats. |
View Sample
Output (HTML Help format).
View Sample Output (HTML Format).
Download
Trial Version (5.2Mb ZIP file). |
| .NET Documentation Tool |
| Automatically creates technical documentation for .NET Framework applications written in C# or VB.NET (including ASP.NET).
Documentation for SQL Server 7/2000/2005 databases and C#/VB.NET components associated with the
web application can also be incorporated into the reports. Documentation is created in
HTML, HTML Help and plain text formats. Additional support for ASP.NET web applications. A useful alternative to the popular NDoc code documentor. |
View Sample
Output (HTML Help format).
View Sample Output (HTML Format).
Download
Trial Version (3Mb ZIP file). |
| SQL
Documentation Tool |
| The SQL Documentation Tool creates technical documentation for Microsoft SQL Server 7.0, 2000 and 2005 databases. Technical documentation is created in HTML and HTML Help formats. The HTML Help format documentation is fully searchable and cross referenced. The SQL Documentation Tool documents SQL Server Tables, Views, Stored Procedures, Triggers, Table Relationships, Jobs and DTS Packages. |
View Sample
Output (HTML Help format).
View Sample Output (HTML Format).
Download
Trial Version (10.3Mb ZIP file). |
| Text Workbench |
| Text Workbench is a file search and replacement utility for text files and Microsoft Office documents. Make rapid file replacements on multiple files and folders full of files. Advanced replacement options include regular expressions support. It even works on remote file systems via FTP. A Regular Expression Laboratory allows advanced pattern matching and replacement expressions to be built and tested. This great utility will make your everyday development tasks much easier!
|
Download
Trial Version (3Mb ZIP file; you have the option to either install directly from this link or save the file for later installation). |
| ASP Spell Check |
| ASPSpellCheck is the easy way to add spell checking capabilities to your ASP or ASP.NET websites, Intranets and web applications. The utility allows you to add spell checking capabilities to any HTML text field or rich content editing text box. It works with all common web browsers, and there are no components or databases to install on the server.
|
Read ASPSpellCheck Review.
View ASPSpellCheck Examples.
Download
Trial Version (3Mb ZIP file; you have the option to either install directly from this link or save the file for later installation). |
Author details
Brett Burridge
has worked as a web developer since 1997 and has developed web applications for a range of corporations, start up busiensses and educational establishments.
Brett is presently employed as an Internet developer and technical writer
through his own company,
Winnersh Triangle Web Solutions Limited.
The company produces a number of
innovative products, including a range of software documentation tools, which include the
ASP Documentation Tool, the .NET Documentation Tool for VB.NET and C#, and the SQL Server Documentation Tool. Other products include The Website Utility, which functions as a website error checker, search engine optimizer and ASP/ASP.NET search engine builder application.
As well as the ASPAlliance, Brett has written articles for Ariadne.ac.uk,
ASPToday, the software documentation portal www.softwaredocumentation.info, and has contributed recipes to the ASP.NET Developer's Cookbook.
links
Outside web development, Brett is interested in travelling (here are my travel logs from New York, Hong Kong and Tokyo), digital photography (here's my photo gallery), tropical fishkeeping
and collecting contemporary works of art by artists such as Doug Hyde.
Contact Brett by emailing
Article history
"Using the VBScript Drives Collection" originally published on ASPWatch.com
on September 22 1999. Republished on ASPAlliance.com on 28 September 2001.
ASP Kitchen: ASPWatch.com
articles: VBScript Drives Collection
|