?
Solved

how to read cdlabels

Posted on 1998-10-13
2
Medium Priority
?
163 Views
Last Modified: 2010-04-30
in a drivelistbox it doesn't say d: [label]
but only d: when I read drive1.drive
if you read drive1.drive when you've selected a harddisk it does return c: [c-drive] but not when accessing a cdrom..
how can I find out the label of the drive?
0
Comment
Question by:fax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 800 total points
ID: 1439781
Here is a code i found somewhere, don't remeber where:

The GetVolumeInformation API call is used to retrieve information about hard drives, floppy drives,
and even CD-ROM drives. Notice how your Windows CD player can recognize which CD is
inserted? It is using the serial number of the CD-ROM (obtained with this API call) to make this
determination. Just substitute the drive letter where it currently says "F:\" and you can check on
any of your drives.

The code that follows will return the serial number (as a long), as well as the volume name and
volume type, such as FAT. However, the text in the returned strings is ended with a null character -
chr$(0). That's the reason for the InStr call -- it only shows the portion of the string up to the null
character. If you don't do that, the DLL showing the MsgBox interprets the null character as the
end of line and no further text is displayed.

Option Explicit 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 cmdTest_Click()
 Dim iSerialNum As Long
 Dim sVolumeLabel As String
 Dim sVolumeType As String
 Dim iRetVal As Long
 sVolumeLabel = Space(255)
 sVolumeType = Space(255)
 iRetVal = GetVolumeInformation("f:\", sVolumeLabel, Len(sVolumeLabel), iSerialNum, 0, 0, sVolumeType, Len(sVolumeType))
 MsgBox "Disk Serial Number: " & iSerialNum & vbCrLf & "Volume Type: " & Left$(sVolumeType, InStr(sVolumeType, Chr$(0)) - 1) & vbCrLf & "Volume Label: " & Left$(sVolumeLabel, InStr(sVolumeLabel, Chr$(0)) - 1)
End Sub
0
 
LVL 4

Expert Comment

by:mcix
ID: 1439782
Great answer MikeP!

For more info about this look here:

http://www.mvps.org/vbnet/code/shell/cdexists.htm
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question