CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 1999
    Location
    China Dalian
    Posts
    58

    How to get CD-ROM's label

    Is there any function to get CD-ROM's label?



  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: How to get CD-ROM's label

    try

    Debug.Print Dir("f:", vbVolume)

    where f: is your cdrom drive

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes


  3. #3
    Join Date
    Jun 1999
    Location
    China Dalian
    Posts
    58

    Re: How to get CD-ROM's label

    Thank you for your reply, but I am not very fimilar with VB, I copy the code you told me, then run it. There are something wrong with the sentence : Debug.Print Dir("f:", vbVolume).
    It is said that "Debug" is a invalid outside procedure. Do I have to write other code before run it?
    Thank you


  4. #4
    Join Date
    Apr 2000
    Posts
    737

    Re: How to get CD-ROM's label

    ok do it this way, put a label in your form called it label1, then in your form load event procedure put this

    Private Sub Form_Load()
    label1.caption = Dir("f:", vbVolume)
    End Sub

    HTH


  5. #5
    Join Date
    Jun 1999
    Location
    China Dalian
    Posts
    58

    Re: How to get CD-ROM's label

    Do you test the code on your computer? why it doesn't work in my program. I do as you told me, but label1.caption ="" after execute the sentence label1.caption = Dir("f:", vbVolume)
    Bother you to check it again!


  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to get CD-ROM's label

    Code is ok, provided you cd - rom is volume f.
    Matter is: you get back an empty string if volume has no label...

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to get CD-ROM's label

    You may want to try with api:
    (from api-guide - download this: it will help you a lot in the future)


    Private 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
    Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: [email protected]
    Dim Serial As Long, VName As String, FSName As String
    'Create buffers
    VName = String$(255, Chr$(0))
    FSName = String$(255, Chr$(0))
    'Get the volume information
    'change "c:\" to your Cd-rom letter
    GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
    'Strip the extra chr$(0)'s
    VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
    FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
    MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
    End Sub

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  8. #8
    Join Date
    Apr 2000
    Posts
    737

    Re: How to get CD-ROM's label

    you should replace f: with your own cdrom drive.


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

Featured