PDA

Click to See Complete Forum and Search --> : How can I exam if there is CD in CDROM


iProgram
Sep 23rd, 2000, 10:44 PM
How can I exam if there is CD in CDROM
I have examed in this way:

On Error Goto NOCD
...............
Dir "E:\aaa.aaa"
Msgbox "CD In CDROM"
Exit Sub
NOCD:
Msgbox "No CD In CDROM"
Exit Sub

But if the fuction is to long,I don't thibk it can work well.
How can I exam it in a "normal" way? API?

Sep 24th, 2000, 12:20 AM
Here you go:D:


Dim fso As FileSystemObject, d As Object, e As Drives, i As Byte
Set fso = CreateObject("Scripting.FileSystemObject")
Set e = fso.Drives
For Each d In e
If d.DriveType = 4 Then
If d.isready = True Then
MsgBox "CD-Rom " & d.DriveLetter & ": is Ready."
Else
MsgBox "CD-Rom " & d.DriveLetter & ": is Not Ready."
End If
End If
Next

stjepan
Oct 13th, 2000, 08:53 PM
Here is a tip from vb-world's tips section :

Retrieving Volume Information and checking if a CD is in the drive

This tip demonstrates how you can receive lots of information about a drive, including the Volume name and number. You can also retrieve information about the type of drive (hard disk, cdrom, removable, etc.)

Module Code

Add the following code to a module:

Declare Function GetVolumeInformation Lib _
"kernel32" 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

Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Public Const DRIVE_CDROM = 5
Form Code

Add one command button to a form with the following code:

Private Sub Command1_Click()

Dim VolName As String, FSys As String, erg As Long
Dim VolNumber As Long, MCM As Long, FSF As Long
Dim Drive As String, DriveType As Long

VolName = Space(127)
FSys = Space(127)

Drive = "F:" 'Enter the driverletter you want

DriveType& = GetDriveType(Drive$)

erg& = GetVolumeInformation(Drive$, VolName$, 127&, _
VolNumber&, MCM&, FSF&, FSys$, 127&)

Print "VolumeName:" & vbTab & VolName$
Print "VolumeNumber:" & vbTab & VolNumber&
Print "MCM:" & vbTab & vbTab & MCM&
Print "FSF:" & vbTab & vbTab & FSF&
Print "FileSystem:" & vbTab & FSys$
Print "DriveType:" & vbTab & DriveType&;

'Is the drive a CDROM, if so, check for a CD

If DriveType& = DRIVE_CDROM Then
Print " (CDROM, ";

If erg& = 0 Then
Print "no CD in the drive)"
Else
Print "CD in the drive)"
End If

Else

Print " (NO CDROM)"

End If

End Sub