Solved

how to read cdlabels

Posted on 1998-10-13
2
158 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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