Solved

how to read cdlabels

Posted on 1998-10-13
2
160 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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