Search Tools Links Login

Determine Disk Type


Given a drive letter, returns the type of disk present, if connected.

Module

Option Explicit

'API Calls

'Function GetDriveType
'lpRootPathName : string that specifies the root directory of the disk to return information about. If lpRootPathName is an empty string, the function uses the root of the current directory.
Public Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

'API Constants
Public Const DRIVE_UNKNOWN = 0
Public Const DRIVE_DOES_NOT_EXIST = 1
Public Const DRIVE_REMOVABLE = 2
Public Const DRIVE_FIXED = 3
Public Const DRIVE_REMOTE = 4
Public Const DRIVE_CDROM = 5
Public Const DRIVE_RAMDISK = 6

Usage

Private Sub Command1_Click()
    'Get the type of the D:\ Drive
    Select Case GetDriveType("D:\")
    Case DRIVE_UNKNOWN
        MsgBox "Type Unknown", vbExclamation
    Case DRIVE_DOES_NOT_EXIST
        MsgBox "Type Unknown", vbCritical
    Case DRIVE_REMOVABLE
        MsgBox "The disk can be removed from the drive", vbInformation
    Case DRIVE_FIXED
        MsgBox "The disk can not be removed from the drive", vbInformation
    Case DRIVE_REMOTE
        MsgBox "The drive is a remote (network) drive", vbInformation
    Case DRIVE_CDROM
        MsgBox "The drive is a CD-ROM drive", vbInformation
    Case DRIVE_RAMDISK
        MsgBox "The drive is a RAM disk", vbInformation
    End Select
End Sub

About this post

Posted: 2019-09-29
By: AndreaTincani
Viewed: 237 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.