|
-
Apr 21st, 2001, 04:09 AM
#1
Thread Starter
Member
hai Friends,
is there any way of finding the Cd drive letter like e or d or ...
srikanth
A.Srikanth
Application Engineer
-
Apr 21st, 2001, 04:11 AM
#2
Frenzied Member
-
Apr 21st, 2001, 08:47 AM
#3
The link gets me a 404 error. I searched for the article but that link was also not working. Maybe I should inform VB Square...
-
Apr 21st, 2001, 11:07 AM
#4
_______
<?>
Code:
'get the first CD Rom drive letter and use it as default
Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
"GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Const DRIVE_CDROM As Long = 5
Private Sub cmdGo_Click()
Dim strDriveLetter As String
' Call the GetFirstCdRomDriveLetter() and store the
' return value in strDriveLetter.
strDriveLetter = GetFirstCdRomDriveLetter()
' Display the drive letter in a message box.
MsgBox strDriveLetter
End Sub
Function GetFirstCdRomDriveLetter() As String
' Declare variables.
Dim lDriveType As Long
Dim strDrive As String
Dim lStart As Long: lStart = 1
' Create a string to hold the logical drives.
Dim strDrives As String
strDrives = Space(150)
' Get the logial drives on the system.
' If the function fails it returns zero.
Dim lRetVal As Long
lRetVal = GetLogicalDriveStrings(150, strDrives)
' Check to see if GetLogicalDriveStrings() worked.
If lRetVal = 0 Then
' Get GetLogicalDriveStrings() failed.
GetFirstCdRomDriveLetter = vbNullString
Exit Function
End If
' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)
Do
' Test the first drive.
lDriveType = GetDriveType(strDrive)
' Check if the drive type is a CD-ROM.
If lDriveType = DRIVE_CDROM Then
' Found the first CD-ROM drive on the system.
GetFirstCdRomDriveLetter = strDrive
Exit Function
End If
' Increment lStart to next drive in the string.
lStart = lStart + 4
' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)
Loop While (Mid(strDrives, lStart, 1) <> vbNullChar)
End Function
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Apr 21st, 2001, 12:07 PM
#5
Fanatic Member
Another way (this will put all the CD-Rom drives in a listbox, and without using Mid, which AFAIK is a little bit faster):
Code:
Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Const DT_CDROM As Long = 5
Private Sub EnumCDDrives(lstDest As ListBox)
Dim sDrive As String
Dim lDrives As Long
Dim lK As Long
' Get all drives
lDrives = GetLogicalDrives()
lstDest.Clear
' Check all drives
For lK = 0 To 25
If (lDrives And 2 ^ lK) <> 0 Then
' Get drive root
sDrive = Chr$(65 + lK) & ":\"
' Check Type
If GetDriveType(sDrive) = DT_CDROM Then
' Add it To the list
lstDest.AddItem sDrive
End If
End If
Next lK
End Sub
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 21st, 2001, 02:16 PM
#6
Frenzied Member
How about this?
Code:
Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
Private Const DT_CDROM As Long = 5
Private Function CDDrive() As Variant
Dim SDRN As Byte
Dim sDrive As String
Dim Drives() As String
Dim Count As Byte
Count = 0
For SDRN = Asc("A") To Asc("Z")
sDrive = Chr$(SDRN) & ":\"
If GetDriveType(sDrive) = DT_CDROM Then
Count = Count + 1
ReDim Drives(0 To Count - 1)
Drives(Count - 1) = sDrive
End If
Next
CDDrive = Drives
End Function
This code returns the drives in an array, STARTING WITH 0.
MicroBasic
Dragon Shadow Trainer
There is no good or evil in the world...only programmers and fools .
-
Apr 21st, 2001, 10:25 PM
#7
Registered User
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|