Results 1 to 3 of 3

Thread: check to see what cd is in the cd drive?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Question

    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?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    try this:


    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
    [Edited by Mark Sreeves on 09-19-2000 at 04:50 AM]
    Mark
    -------------------

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    way with api
    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
    this works too!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width