Detect If CD/Floppy Disk Is In The Drive

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 CommandButton (named Command1) and 1 DriveListBox (named Drive1) to your form.
'Choose in the DriveListBox the drive you want to detect, and press the button.
'Insert this code to the 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

'Insert this code to your form:

Private Sub Command1_Click()
erg& = GetVolumeInformation(Drive1.Drive, VolName$, 127&, _
VolNumber&, MCM&, FSF&, FSys$, 127&)
If erg& = 0 Then
MsgBox "There is no media in the drive"
MsgBox "There is a media in the drive"
End If
End Sub

Go Back