-
how to detect cd rom drive
[Originally posted by liju john]
is there any vb code /api function to detect
the name of cdrom drive in our computer?
-
Re:how to detect cd rom drive
[Originally posted by Ron Weller]
ÿ ' **********************************************************************
ÿ '
ÿ ' FUNCTION:
ÿ 'ÿ ÿ GetFirstCdRomDriveLetter()
ÿ '
ÿ ' PURPOSE:
ÿ 'ÿ ÿ Finds the first CD-ROM device and then returns its drive letter.
ÿ '
ÿ ' ARGUMENTS:
ÿ 'ÿ ÿ None
ÿ '
ÿ ' RETURNS:
ÿ 'ÿ ÿ A string that represents the first CD-ROM drive letter. If the
ÿ 'ÿ ÿ function fails for any reason, it returns vbNullString.
ÿ '
ÿ ' **********************************************************************
ÿ Declare Function GetDriveType Lib "kernel32" Alias _
ÿ ÿ ÿ "GetDriveTypeA" (ByVal nDrive As String) As Long
ÿ Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
ÿ ÿ ÿ "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ÿ ÿ ÿ ByVal lpBuffer As String) As Long
ÿ Public Const DRIVE_CDROM As Long = 5
ÿ 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
'Following is an example of calling the GetFirstCdRomDriveLetter() function from a macro (Sub procedure):
ÿ Sub Main
ÿ ÿ ÿ 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
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks