How to get detailed drive information through COM

On January 10, 2008, in ColdFusion, by Anuj Gakhar

Back in 2001, when CFComet was live, I wrote a little script to read detailed drive information (windows only) via COM. I thought it might be a good idea to post it here as well. This code makes use of the FileSystemObject and displays some useful information. I did a little search and its still Live. Here is the code :-

<!— Try to Create the Object —><CFTRY>
<CFCATCH type="ANY">
<!— Get all the existing drives . This can be any type of drives.
Fixed drives, network drives etc. —>
<CFSET Drives = FSO.Drives>
<!— Display the no. of drives —>
Number of Drives : #Drives.Count#<BR>
<!— Make a table to show the results —><TABLE cellspacing="1" cellpadding="5">
<TD>Total Size</TD>
<TD>Free Space</TD>
<TD>Available Space</TD>
<TD>Serial No.</TD>
<!— This is a COM collection so we cant use conditional loops, index loops and other loops.
ColdFusion provides us a nice way of looping over COM collections so we are using that here .—>
<CFLOOP COLLECTION="#Drives#" ITEM="this">
<!— remove the below "CFIF" statement if you havent disabled any of your floppy drives .—>
<CFIF this.DriveLetter is not "A">
<!— Display the Drive Letter —>
<!—Display the Total size —><TD><CFIF this.isReady AND ISDefined("this.TotalSize")>
#NumberFormat(round(evaluate(this.TotalSize/1000000)))# Mb
<!— Display the free space —><TD>
<CFIF this.isReady AND ISNumeric(this.FreeSpace)>
#NumberFormat(round(evaluate(this.FreeSpace/1000000)))# Mb
<!— Display the available space —><TD>
<CFIF this.isReady AND IsNumeric(this.AvailableSpace)>
#NumberFormat(round(evaluate(this.AvailableSpace/1000000)))# Mb
<!— Display the serial number —><TD>
<CFIF this.isReady AND LEN(this.SerialNumber)>
<!— Display the path —><TD>#this.path#</TD>
<!— These are the constants returned by Drive.DriveTypeConst DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5
So we’ll use CFSWITCH statements to display the actual type —>
<CFSWITCH expression="#this.DriveType#">
<CFCASE value="1">Removable</CFCASE>
<CFCASE value="2">Fixed</CFCASE>
<CFCASE value="3">Network</CFCASE>
<CFCASE value="5">Ram Disk</CFCASE>
<!— Display if the Drive is ready —><TD>#this.isReady#</TD>
<!— Here we have to display the drive name. Before that, we willcheck if it is a network drive or not. If it is a network drive,
then we display the ‘sharename’; otherwise, we display the ‘volumename’.
<CFIF this.isReady>
<CFIF this.DriveType IS "3">
<!— #this.ShareName# —>
<!— Display the type of Filesystem —>
<TD><CFIF this.isReady>#this.FileSystem#</CFIF></TD>

Tagged with:  

4 Responses to How to get detailed drive information through COM

  1. thanks! this may be very useful for the project I’m currently working on.

  2. Anuj Gakhar says:

    @Aaron, glad you liked it. As I wrote, this was done years ago, so its good to know it still is useful.

  3. Ian says:

    This looks like an old post – but is there any way to make this run on a network drive?

  4. Anuj Gakhar says:

    @Ian, I think a mapped drive would work just the same as a local drive. Did you try doing that?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 446 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: