AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani
:: Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive

Author  

Andrea Tincani

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

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

:: Navigation

Home

Files and Disks Tips

Previous Tip

Next Tip

:: Search this site
Google
Web andreavb.com
:: Sponsored Links



AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani