CodeItBetter Programming Another VB Programming Blog

How to list down all necessary Drive information

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'System & API - How to list down all necessary Drive information
'You need to set reference to Microsoft Scripting Runtime

Public Function DriveInfo(Optional strDriveLetter As String = "C")
    Dim fldr As Folder
    Dim fso As New Scripting.FileSystemObject
    Dim drv As Scripting.Drive
    Dim strType As String
    'Make sure there is only one drive letter
    If Len(strDriveLetter) > 1 Then
        MsgBox "Unknown Drive Letter"
        Exit Function
    End If
    'Make sure the drive exists
    If Not fso.DriveExists(strDriveLetter & ":") Then
        MsgBox "Unknown Drive. Drive doesn't exist."
        Exit Function
    End If
    Set drv = fso.GetDrive(fso.GetDriveName(strDriveLetter & ":"))
    Debug.Print vbCrLf & "Drive Information for " & UCase$(strDriveLetter) & " Drive"
    Debug.Print "============================="
    Debug.Print "Available space   : " & FormatNumber(drv.AvailableSpace / 1024, 0) & " KB"
    Debug.Print "Drive letter      : " & drv.DriveLetter
    Select Case drv.DriveType
        Case 0: strType = "Unknown"
        Case 1: strType = "Removable"
        Case 2: strType = "Fixed"
        Case 3: strType = "Network"
        Case 4: strType = "CD-ROM"
        Case 5: strType = "RAM Disk"
    End Select
    Debug.Print "Drive type        : " & strType
    Debug.Print "Drive file system : " & drv.FileSystem
    Debug.Print "Drive free space  : " & FormatNumber(drv.FreeSpace / 1024, 0) & " KB"
    Debug.Print "Drive is ready    : " & drv.IsReady
    Debug.Print "Drive path        : " & drv.Path
    Debug.Print "Root folder       : " & drv.RootFolder
    Debug.Print "Serial number     : " & drv.SerialNumber
    Debug.Print "Share name        : " & drv.ShareName
    Debug.Print "Total size        : " & FormatNumber(drv.TotalSize / 1024, 0) & " KB"
    Debug.Print "Volume  name      : " & drv.VolumeName
End Function

Related posts:

  1. How to get free disk space of C drive (in two ways)
  2. How to get OS information from the system (in two ways)
  3. How to find the number of a name, used in a numerology program
  4. How to List all the DLL files in the C:\WINDOWS\SYSTEM directory.
  5. How to Get Task Bar Information
  6. How to clear Start Menu -> Run MRU list
  7. How to return the drive type
  8. How to get Printer information like Status, Share Name, etc.
  9. How to get User’s local information
  10. How to list all the objects in a Database using DAO.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.