|
-
Nov 3rd, 1999, 08:07 PM
#2
New Member
Hi!
I found sample code for recognizing which drive on computer is CD:
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) _
As Long
Private Const DRIVE_UNKNOWN = 0
Private Const DRIVE_NOROOT = 1
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 Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Function dhGetDrivesByString(colDrives As Collection) _
As Integer
Dim strBuffer As String
Dim lngBytes As Long
Dim intPos As Integer
Dim intPos2 As Integer
Dim strDrive As String
Set colDrives = New Collection
strBuffer = Space(255)
' Get the logical drive string
lngBytes = GetLogicalDriveStrings( _
Len(strBuffer), strBuffer)
intPos2 = 1
intPos = InStr(intPos2, strBuffer, vbNullChar)
Do Until intPos = 0 Or intPos > lngBytes
' Parse out the drive letter
strDrive = Mid(strBuffer, intPos2, intPos - intPos2)
' Add it to the collection
colDrives.Add strDrive, strDrive
' Find the next drive letter
intPos2 = intPos + 1
intPos = InStr(intPos2, strBuffer, Chr(0))
Loop
dhGetDrivesByString = colDrives.Count
End Function
And use of function:
Dim lngType As Long
Dim colDrives As Collection
Dim varDisk As Variant
If dhGetDrivesByString(colDrives) > 0 Then
For Each varDisk In colDrives
lngType = GetDriveType(CStr(varDisk))
If lngType = DRIVE_CDROM Then
' varDisk is label of CD-ROM
End If
Next
End If
[This message has been edited by Maxi (edited 11-04-1999).]
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
|