[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to read cdlabels

Posted on 1998-10-13
2
Medium Priority
?
166 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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

649 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