Accessing information about system drives...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you access the volume label for a hard drive through C#? I am very much a beginner with C# at the moment and am developing a windows explorer program to help me learn. I have tried the GetLogicalDrives method of the Directory class and have also used the FullName property of the DirectoryInfo class, but they only return the drive letter (ex...C:\, or A:\). I would like to be able to list the volume label of the disk (ex...Local Disk, etc).

Also, I found some sample code which showed how to use DLLImport to access the GetDriveType method of the Kernel32 dll. This is great, but on my system, both my zip and floppy drive return as Removeable Drives. What is the best way to determine the type of drive, so that I know if it a floppy drive or a zip drive, or some other removeable drive.

Thanks for any help.
 
Using the System.Management classes and WMI class Win32_Logicaldisk, it's
possible to check the drivetype and mediatype values, but this will only
tell you that a removeable drive (drivetype) is a floppy drive (different
mediatypes) or any other removeable drive (mediatype 11).

Willy.

Jon1996 said:
How do you access the volume label for a hard drive through C#? I am very
much a beginner with C# at the moment and am developing a windows explorer
program to help me learn. I have tried the GetLogicalDrives method of the
Directory class and have also used the FullName property of the
DirectoryInfo class, but they only return the drive letter (ex...C:\, or
A:\). I would like to be able to list the volume label of the disk
(ex...Local Disk, etc).
Also, I found some sample code which showed how to use DLLImport to access
the GetDriveType method of the Kernel32 dll. This is great, but on my
system, both my zip and floppy drive return as Removeable Drives. What is
the best way to determine the type of drive, so that I know if it a floppy
drive or a zip drive, or some other removeable drive.
 
Back
Top