Mega Code Archive

 
Categories / Delphi / Examples
 

Getvolumeinformation

function GetLastErrorString : string; begin SetLength(Result, MAX_PATH); SetLength(Result, FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM OR FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, GetLastError, 0, pchar(Result), MAX_PATH, nil) - 2); end; function API_GetVolumeInformation(Root : string; out VolName, FileSysName : string; out VolSerial, FileMaxLen, FileFlags : DWORD) : boolean; begin SetLength(VolName, MAX_PATH); SetLength(FileSysName, MAX_PATH); Result := GetVolumeInformation(pchar(Root), pchar(VolName), MAX_PATH, @VolSerial, FileMaxLen, FileFlags, pchar(FileSysName), MAX_PATH); if (Result) then begin SetLength(VolName, StrLen(pchar(VolName))); SetLength(FileSysName, StrLen(pchar(FileSysName))); end else begin SetLength(VolName,0); SetLength(FileSysName,0); VolSerial := 0; end; end; procedure TfApp.Button1Click(Sender: TObject); var RPN, VolN : string; VSN : DWORD; MCL : DWORD; FSF : DWORD; FileSysN : string; begin RPN := '\'; if (API_GetVolumeInformation(RPN, VolN, FileSysN, VSN, MCL, FSF)) then Application.MessageBox(pchar(VolN + ' | ' + FileSysN + ' | ' + IntToStr(VSN) + ' | ' + IntToStr(MCL)), pchar('Success'), MB_OK) else Application.MessageBox(pchar(GetLastErrorString), pchar('Error'), MB_OK); end; ********************************************************************************* Hi! This works for me: 8< --------------------------------------------------------------------------- -------------- //this is from a class of mine Procedure TLocalDrive.ReadDriveInfo; VAR l_Flags : DWORD; l_Label : AnsiString; l_MaxLength : DWORD; l_Name : AnsiString; l_Root : AnsiString; l_Serial : PDWORD; begin {get volume info from WinAPI} l_Root := GetRoot; // ie 'A:\' SetLength(l_Label, 12); SetLength(l_Name, 12); IF GetVolumeInformation(PAnsiChar(l_Root), //root dir PAnsiChar(l_Label), //label buffer Length(l_Label), //label buffer length l_Serial, //serial number l_MaxLength, //max. filename length l_Flags, //file system flags PAnsiChar(l_Name), //file system name Length(l_Name) //file system name length ) then BEGIN FLabel := l_Label; FSerial := l_Serial^; FMaxFileName:= l_MaxLength; FFSflags := l_Flags; FFSname := l_Name; END else BEGIN RAISE CreateDriveException(FName, GetLastError); END; end;{TLocalDrive.ReadDriveInfo}