Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find the Type of my drive

Status
Not open for further replies.

Kori

Programmer
Oct 17, 2000
35
US
I am in the need of finding out what Drive I am currently on.

For example if you go to the properties of your hard disk it says

Type: Local Disk

Or for the network:

Type: Network Connection

Anyone know how to go get these?
 
Two ways of doing it: using API or the FileSystemObject..

*** API ***

Private Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6

Private Sub GetDriveTypeWithAPI()

Dim liDriveType As Long
Dim lsDescription As String

liDriveType = GetDriveType("c:\")

Select Case liDriveType

Case 2: lsDescription = "Removable"
Case 3: lsDescription = "Fixed"
Case 4: lsDescription = "Network"
Case 5: lsDescription = "CD-ROM"
Case 6: lsDescription = "RAM Disk"
Case Else: lsDescription = "Unknown"

End Select

MsgBox "Drive type: " & lsDescription

End Sub

*** FSO ***

Private Sub GetDriveTypeWithFSO()

Dim loFSO As FileSystemObject
Dim loDrive As Drive
Dim lsDescription As String

Set loFSO = New FileSystemObject
Set loDrive = loFSO.GetDrive("c:\")

Select Case loDrive.DriveType

Case 0: lsDescription = "Unknown"
Case 1: lsDescription = "Removable"
Case 2: lsDescription = "Fixed"
Case 3: lsDescription = "Network"
Case 4: lsDescription = "CD-ROM"
Case 5: lsDescription = "RAM Disk"

End Select

MsgBox "Drive type: " & lsDescription

Set loFSO = Nothing
End Sub

Remedy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top