DEVELOPER TOOLS
ASP Documentation
Tool
.NET Documentation
Tool
PHP Documentation
Tool
SQL Documentation
Tool
VB6 Documentation
Tool
Indexing Service
Companion
The Website UtilityTECHNICAL
ARTICLES
ASP
ASP.NET
JavaScript
Transact SQL
Software Reviews
PHOTO GALLERIES
Canon EOS 300D
Samples
Red Arrows 2004
Living Coasts
Akihabara Maids!
Web Page Backgrounds
More Galleries...
TRAVEL LOG
2007: Tokyo
2006: Hong Kong
2005: New York City
NEW STUFF
ASP Spell Check
Code Documentors
The Website Utility
Search Engine Optimisation
Build an ASP Search Engine
My Tropical Fishtank
Text WorkBench
Other New Stuff...
POPULAR STUFF
Regular
Expressions
ASP Documentation Tool
Index
Server & ASP
JavaScript Ad Rotator
LINKS
Business Website
ASPAlliance Articles
Software Documentation Portal

|
Home > Articles
Using the VBScript Drives Collection in ASP
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. A future article shows how to build 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 developer 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 Windows and ASP.NET applications written in C# or VB.NET and SQL Server 7/2000/2005 or Microsoft Access databases associated with the
application. 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 (5Mb ZIP file). |
| SQL
Documentation Tool |
| The SQL Documentation Tool creates technical documentation for Microsoft SQL Server 7.0 and 2000 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 and Table Relationships. |
View Sample
Output (HTML Help format).
View Sample Output (HTML Format).
Download
Trial Version (10.3Mb ZIP file). |
| Indexing Service Companion |
|
The Indexing Service Companion is a Windows application that extends the functionality of the Microsoft Windows Indexing Service so that it is able to index content from remote websites and also from ODBC databases. As such it can be used as a low cost alternative to Sharepoint Portal Search Services.
|
Try Sample Search Facility.
Download
Trial Version (1.7Mb ZIP file). |
| The Website Utility |
| The Website Utility examines websites for errors and
areas that need to be optimised for search engines by using a built in web crawling engine.
Errors checked for include broken or moved hyperlinks, missing page titles and missing meta tags.
It also generates HTML for use in creating website site maps (table of contents pages - like this one), and is
able to create both client-side JavaScript Search Engines and server-side ASP Search Engines for a website. |
View Sample Output (HTML Format).
Download
Trial Version (3Mb ZIP file). |
|
|