Web Robot View of http://authors.aspalliance.com/brettb/VBScriptDrivesCollection.asp

Page Item Value
Title VBScript Drives Collection
Description Sample VBScript (ASP) code showing how to use check that the specified file or folder exist within the file system
Keywords asp, file, folder, vbscript, exists, permission, permissions, access
Robots Meta Tag  
Page Content   ASP Kitchen
Search: Go Home | ASP Articles | ASP.NET Articles | Tools | Table Of Contents | What's New

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 An ASP disk space monitor . Sams Teach Yourself Web Development With ASP in 24 Hours . Start learning ASP with this introductory guide. 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).
Index Server Companion The Index Server Companion is a Windows application that extends the functionality of Microsoft Index Server 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 Site Server 3.0 Search. View Product Documentation (119K ZIP file).
Try Sample Search Facility .
Download Trial Version (1.7Mb ZIP file).
ASP.NET Documentation Tool Automatically creates developer documentation for ASP.NET web applications written in C# or VB.NET. Documentation for SQL Server 7/2000 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. View Sample Output (HTML Help format).
View Sample Output (HTML Format).
Download Trial Version (727K 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).
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).
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). Author details Brett Burridge spent two years working in the University of Essex Computing Service, before moving to The Internet Applications Group in the Autumn of 1999, where he developed e-Business applications for a range of corporate clients and dot-com start ups. 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 the popular ASP Documentation Tool , the Index Server Companion , the ASP.NET Documentation Tool , the SQL Server Documentation Tool and The Website Utility . The company is also available for web application design and development at reasonable rates, primarily using Microsoft technologies (ASP, ASP.NET, Visual Basic, SQL Server) but also using open source technologies such as PHP, MySQL and Perl. Specialist services include development of search solutions using Microsoft's Index Server and Site Server 3.0 Search. As well as the ASPAlliance, Brett has written articles for Ariadne.ac.uk and ASPToday , and has contributed recipes to the ASP.NET Developer's Cookbook . links Outside web development, Brett is interested in digital photography (here's my photo gallery ), tropical fishkeeping and collecting contemporary works of art by artists such as Doug Hyde .

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

page content copyright Brett Burridge 1998 - 2004.
Image Alt Tags ASPAlliance
ASP Script output
Drive A is not ready
Drive A is ready for use
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Product Documentation
Try Sample Search Facility
Download Trial Version
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Sample Output (HTML Help format)
View Sample Output (HTML Format)
Download Trial Version
View Sample Output (HTML Format)
Download Trial Version
Download Trial Version of Text Workbench
Index Server Companion - allows Index Server to index content from remote websites and ODBC databases!!!
Download a Free ASP Documentation Tool Now!
Google
Search Engine Builder - Build a search engine for your website!
Internal Links http://authors.aspalliance.com/brettb/Default.asp (3 links in this page) [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/ASPDiskMonitoringScript.asp (2 links in this page) [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/TableOfContents.asp (2 links in this page) [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/ASPWatchArticles.asp (2 links in this page) [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/ASP.NetArticles.aspx [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/Tools.asp [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/What'sNew.aspx [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/ClassicASPArticles.asp [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/Links.asp [ Robot View of this URL ]
http://authors.aspalliance.com/brettb/redirector.asp [ Robot View of this URL ]
http://authors.aspalliance.com/ [ Robot View of this URL ]

Reporting Main Page

Report generated by The Website Utility 2.8