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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetDriveName Method 1

Status
Not open for further replies.

mishmish

Programmer
May 25, 2001
27
US
Hi,

Does anyone know how to use the GetDriveName method in VB? The help files on this aren't very extensive. If you know how to do, can you provide an example? I'm trying to get the drive letter for a user's cd rom drive.

Thanks,
mishmish
 
If your looking for the drive letter, why not use the following method:

Dim fs As scripting.FileSystemObject
Dim Drive As scripting.Drive
Dim drivecollection As scripting.Drives
Dim intDrive As Integer 'drivenumber

On Error GoTo ErrorOpen

Set fs = CreateObject("Scripting.FileSystemObject")
Set drivecollection = fs.Drives

intDrive = 0

For Each Drive In drivecollection
'pass drive letters to an array of buttons
cmdDrive(intDrive).Caption = Drive.DriveLetter & ":"
cmdDrive(intDrive).Visible = True
intDrive = intDrive + 1
Next

Exit Sub

ErrorOpen:
If Err.Number = 68 Then 'no disc in drive

Else
If Err.Number = 71 Then 'drive not ready
Else
strBericht = "Failure " & CStr(Err.Number) & " :" & vbCr & _
Err.Description
MsgBox strBericht, vbExclamation, "Alert!"
End If
End If



you can determine the drive type the following way:

Set Drive = fs.GetDrive(strDrive) 'strDrive contains a directory path
Select Case Drive.DriveType
Case 0: strDriveType = "Unknown"
Case 1: strDriveType = "Removable"
Case 2: strDriveType = "Fixed"
Case 3: strDriveType = "Network"
Case 4: strDriveType = "CD-ROM"
Case 5: strDriveType = "RAM Disk"
End Select

you can determine the name of the drive the following way:

If Drive.DriveType = 3 Then
strDriveName = Drive.ShareName
Else
strDriveName = Drive.VolumeName
End If

Hope this helps.

 
Painkiller,

I am trying to use this bit of code to determine weather or not a computer has an A: drive. (So I can tell if it is a laptop or not.) The problem I have is that when running I get an error that it doesn't know what scripting.FileSystemObject is.

I have made a reference to Windows Script Host Object Model. Is there something else I need to be doing?

Thanks. :)
 
Hi alforjj,

You need to make a reference to the Microsoft Scripting Runtime library (just Microsoft Scripting Runtime in the references window), not the windows scripting host object model.

After that, you can use the filesystem object.

Btw, I thought even laptops had a: drives ?

Greetz,

Painkiller
 
Thanks, that worked great.

We are using IBM T22 Laptops. They will only let you have either a CD-ROM or an A: drive in at once. Two million laptops on the market, and we have to go and buy the 1% that doesn't have both drives in simultaneously AND that hase multipule sets of drivers. Corporate mentality...gota love it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top