BCS Get Drive Volume ID Delphi


There are those occasions when the volume id from a disk drive is needed. The following code snippet identifies how to retrieve the volume id in Delphi.
[codesyntax lang=”delphi”]

function TBCSListFilesXC.VolumeName(DriveName: Char): string;
var
  max, Flags: DWORD;
  buf: array [0 .. MAX_PATH] of Char;
begin
  try
    Windows.GetVolumeInformation(PChar(DriveName + ':\'), buf, sizeof(buf), nil,
      max, Flags, nil, 0);
    Result := StrPas(buf);
  except
    Result := '';
  end;
end;

[/codesyntax]
To invoke the above function by issuing a similar command.
[codesyntax lang=”delphi”]

    vid := VolumeName(drive);

[/codesyntax]
The contents of the drive’s volume id is now in the vid variable.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *