Solved

how to read cdlabels

Posted on 1998-10-13
2
154 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
2 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 200 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now