How do I get the letter of the CDROM drive? Or get the root directory of the drive my program is on?
Printable View
How do I get the letter of the CDROM drive? Or get the root directory of the drive my program is on?
Hello,
I never needed to find the CD, but to figure out what drive your app is on try this:
Hope this helps,Code:MsgBox Left(App.Path, 2)
Hi !
I have code for finding CD_ROM(s) :
In Declare module:
Declare Function GetLogicalDriveStrings Lib "kernel32.dll" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Declare Function GetDriveType Lib "kernel32.dll" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Const DRIVE_REMOVABLE = 2 'A floppy drive or some other removable-disk drive.
Public Const DRIVE_FIXED = 3 'A hard drive.
Public Const DRIVE_REMOTE = 4 'A network drive or a drive located on a network server.
Public Const DRIVE_CDROM = 5 'A CD-ROM drive.
Public Const DRIVE_RAMDISK = 6 'A RAM disk.
In Execution Module: (Form or others ...)
Private Sub Command1_Click()
Dim strdrivenames As String
Dim strthisdrive As String
Dim lngcpt As Long
Dim lnglength As Long
Dim lngdrivetype As Long
strdrivenames = Space(255)
lnglength = GetLogicalDriveStrings(255, strdrivenames)
For lngcpt = 1 To lnglength Step 4
strthisdrive = Mid(strdrivenames, lngcpt, 3)
lngdrivetype = GetDriveType(strthisdrive)
Select Case lngdrivetype
Case DRIVE_REMOVABLE: MsgBox strthisdrive & " is a removable-disk drive."
Case DRIVE_FIXED: MsgBox strthisdrive & " is a hard drive."
Case DRIVE_REMOTE: MsgBox strthisdrive & " is a network drive or a drive located on a network server."
Case DRIVE_CDROM: MsgBox strthisdrive & " is a CD-ROM drive."
Case DRIVE_RAMDISK: MsgBox strthisdrive & " is a RAM disk."
Case Else: MsgBox strthisdrive & " comes from X-Files ;)."
End Select
Next lngcpt
End Sub
You can limit the test of lngdrivetype to DRIVE_CDROM of course ;)
I hope it's oki for you ... bye.
Thanks, Im sure that code will come in handy. But for now, I just opened to root Directory by useing " ..\ " to back one directory. Thanks again