How can i check to see, if any, cd is in the cd drive, and if there is a cd in the drive, what cd it is?
Printable View
How can i check to see, if any, cd is in the cd drive, and if there is a cd in the drive, what cd it is?
try this:
[Edited by Mark Sreeves on 09-19-2000 at 04:50 AM]Code:
Option Explicit
Private Sub Command1_Click()
On Error GoTo errHan:
Dim strLabel As String
' check there is a cd in the drive
Dir "d:\"
' should be 0
strLabel = Dir("d:\", vbVolume)
If strLabel = "" Then
MsgBox "CD has no label"
Else
MsgBox "D drive contains: " & strLabel
End If
Exit Sub
errHan:
' no cd in drive
MsgBox Err.Number & " " & Err.Description
End Sub
way with api
this works too!Code:'in a module
Public Declare Function GetVolumeInformation Lib "kernel32.dll" Alias _
"GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer _
As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
'on a command button
Dim volname As String
Dim sn As Long
Dim snstr As String
Dim maxcomplen As Long
Dim sysflags As Long
Dim sysname As String
Dim retval As Long
Private Sub Command1_Click()
volname = Space(256)
sysname = Space(256)
retval = GetVolumeInformation("D:\", volname, Len(volname), sn, maxcomplen, _
sysflags, sysname, Len(sysname))
volname = Trim$(volname)
sysname = Trim$(sysname)
snstr = Trim(Hex(sn))
snstr = String(8 - Len(snstr), "0") & snstr
snstr = Left(snstr, 4) & "-" & Right(snstr, 4)
Debug.Print "Volume Name: "; volname
Debug.Print "Serial Number: "; snstr
Debug.Print "File System: "; sysname
End Sub