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.
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
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?
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.