Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

VS Script – Drive Info

Posted on July 18, 2013September 2, 2019 By David Kittell
'DriveInfo.vbs - Show information for local & network drives.
'Note: A bug in WScript results in sizes over 2 GB being misreported.
'© Bill James - billjames.geo@yahoo.com - rev 16 Feb 2000
Option Explicit
Dim WshShell,FSO,Drv,Dtype,Dfree,Dtot
Dim Dname,Dpct,Dused,Dserial,Dinfo
Set WshShell=WScript.CreateObject("WScript.Shell")
Set FSO=CreateObject("Scripting.FileSystemObject")
For each Drv in FSO.Drives
  If Drv.DriveType=0 Then Dtype="Unknown   "
  If Drv.DriveType=1 Then Dtype="Removable"
  If Drv.DriveType=2 Then Dtype="Fixed           "
  If Drv.DriveType=3 Then Dtype="Network      "
  If Drv.DriveType=4 Then Dtype="CD-ROM    "
  If Drv.DriveType=5 Then Dtype="RAM Disk   "
  If Drv.IsReady Then
    If Drv.DriveType=4 Then
      Dfree="N/A"
    ElseIf Drv.FreeSpace<1024^2 Then
      Dfree=FormatNumber(Drv.FreeSpace/1024,0)&" KB"
    ElseIf Drv.FreeSpace<10240^2 Then
      Dfree=FormatNumber(Drv.FreeSpace/(1024^2),2)&" MB"
    Else
      Dfree=FormatNumber(Drv.FreeSpace/(1024^2),0)&" MB"
    End If
    If Drv.TotalSize<1024^2 Then
      Dtot=FormatNumber(Drv.TotalSize/1024,0)&" KB"
    ElseIf Drv.TotalSize<10240^2 Then
      Dtot=FormatNumber(Drv.TotalSize/(1024^2),2)&" MB"
    Else
      Dtot=FormatNumber(Drv.TotalSize/(1024^2),0)&" MB"
    End If
    If Drv.VolumeName="" Then
      Dname="(None)"
    Else
      Dname=Drv.VolumeName
    End If
    Dused=Drv.TotalSize-Drv.FreeSpace
    If Dused<1024^2 Then
      Dused=FormatNumber(Dused/1024,0)&" KB"
    ElseIf Dused<10240^2 Then
      Dused=FormatNumber(Dused/(1024^2),2)&" MB"
    Else
      Dused=FormatNumber(Dused/(1024^2),0)&" MB"
    End If
    If Drv.DriveType=4 Then
      Dpct="N/A"
    Else
      Dpct=FormatPercent(Drv.FreeSpace/Drv.TotalSize,1)
    End If
    If Drv.DriveType=5 Then
      Dserial="N/A"
    Else
      Dserial=Hex(Drv.SerialNumber)
    End If
    Dinfo=Dinfo&"Drive "&Drv.DriveLetter&_
      ":"&vbTab&vbTab&vbTab&_
      "Drive Type:  "&Dtype&vbTab&_
      "File System:  "&Drv.FileSystem&vbCRLF&_
      "Total Size:  "&Dtot&vbTab&_
      "Free Space:  "&Dfree&vbTab&_
      "Volume Label:  "&Dname&vbCRLF&_
      "Used Space: "&Dused&vbTab&_
      "Percent Free: "&Dpct&vbTab&_
      "Serial Number: "&Dserial&vbCRLF&vbCRLF
  Else
    Dinfo=Dinfo&"Drive "&Drv.DriveLetter&_
      ":"&vbTab&vbTab&vbTab&_
      "Drive Type:  "&Dtype&vbTab&_
      "(No Media in Drive)"&vbCRLF&vbCRLF
  End If
Next
WshShell.popup "Note:  A bug in WScript results in " & _
  "sizes over 2 GB being misreported." & vbcrlf & _
  vbcrlf & Dinfo,,"Information on Available Drives",0
Originally Posted on July 18, 2013
Last Updated on September 2, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Windows VBS

Post navigation

Previous post
Next post

Related Posts

MSSQL DateTime Conversions

Posted on June 23, 2014December 26, 2018

Sometimes a basic function like MSSQL Format Date Function can not work as you do not have permission to create a function or you simply need something quick. To get day of week from DateTime column and order it by the proper day of week order. This is rather easy…

Read More

Get User Details Function

Posted on August 6, 2013October 26, 2015

— Get User’s First Name, Last Name SELECT dbo.GetUserDetails(120, 1) — Get User’s Last Name, First Name SELECT dbo.GetUserDetails(120, 4) — Get User’s Username SELECT dbo.GetUserDetails(120, 2) — Get User’s Email Address SELECT dbo.GetUserDetails(120, 3) IF OBJECT_ID(N’dbo.GetUserDetails’) IS NOT NULL DROP FUNCTION dbo.GetUserDetails GO CREATE FUNCTION dbo.GetUserDetails ( @userid INT…

Read More

Import Excel Spreadsheet into DataGrid

Posted on March 25, 2013October 26, 2015

Originally found at http://blueraiden.exofire.net/blog/import-excel-spreadsheet-data-to-datagridview-using-vb-net For the code to work you need to first add a DataGridView and a Button in design view and have a valid file path for the Excel file. Imports System.Data.SqlClient Public Class Form1 Dim MyConnection As System.Data.OleDb.OleDbConnection Dim ExcelDataSet As System.Data.DataSet Dim ExcelAdapter As System.Data.OleDb.OleDbDataAdapter Private…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes