How to display label of unnamed drive ?

Posted by iira on Stack Overflow See other posts from Stack Overflow or by iira
Published on 2010-05-17T06:06:09Z Indexed on 2010/05/17 6:10 UTC
Read the original article Hit count: 212

Filed under:
|

I want to get the name or label of drive.

I use this function :

function GetVolumeLabel(DriveChar: Char): string;
var
  NotUsed:     DWORD;
  VolumeFlags: DWORD;
  VolumeInfo:  array[0..MAX_PATH] of Char;
  VolumeSerialNumber: DWORD;
  Buf: array [0..MAX_PATH] of Char;
begin
    GetVolumeInformation(PChar(DriveChar + ':\'),
    Buf, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
    VolumeFlags, nil, 0);

    SetString(Result, Buf, StrLen(Buf));   { Set return result }
    Result:=AnsiUpperCase(Result)
end;

For example, here're my drives in Windows Explorer :

Local Disk (C:)
Data (D:)
DVD RW Drive (E:)

The output of the code :

C: 
D: DATA
E:

The labels of C and E are empty. What winapi/function should I use to display the label of unnamed drive (C and E)?

© Stack Overflow or respective owner

Related posts about delphi

Related posts about drives