windows SDK   help
The GetVolumeInformation function returns information about a file system and volume whose root directory is specified. BOOL GetVolumeInformation(    LPCTSTR lpRootPathName, // address of root directory of the file system 
    LPTSTR lpVolumeNameBuffer, // address of name of the volume 
    DWORD nVolumeNameSize, // length of lpVolumeNameBuffer 
    LPDWORD lpVolumeSerialNumber, // address of volume serial number 
    LPDWORD lpMaximumComponentLength, // address of system's maximum filename length
    LPDWORD lpFileSystemFlags, // address of file system flags 
    LPTSTR lpFileSystemNameBuffer, // address of name of file system 
    DWORD nFileSystemNameSize  // length of lpFileSystemNameBuffer 
   );
 
用法?
strlabel:string;
serial_no:string;
strtype:stringGetVolumeInformation('c:\', strlabel,255, serial_no, 0, 0, strtype, 255);
试试?我没测试可能要对数据类型转换一下。  

解决方案 »

  1.   

    type
     
      TVolumeInformation = record
         VolumeName  : string;
         VolumeSerialNumber,
         MaximumComponentLength,
         FileSystemFlags : integer;
         FileSystemName : string;
       end; function GetVolumeInformation (D : char; var V : TVolumeInformation) : boolean;
     var
       O : integer;
     begin
       O := SetErrorMode (SEM_FAILCRITICALERRORS);
       try
         with V do
         begin
           SetLength (VolumeName, MAX_PATH);
           SetLength (FileSystemName, MAX_PATH);
           VolumeSerialNumber := 0;
           MaximumComponentLength := 0;
           FileSystemFlags := 0;
           Result := Windows.GetVolumeInformation (PChar (D+':\'), PChar (VolumeName), MAX_PATH,
             @VolumeSerialNumber, MaximumComponentLength, FileSystemFlags,
             PChar (FileSystemName), MAX_PATH);
           RealizeLength (VolumeName);
           RealizeLength (FileSystemName)
         end
       finally
         SetErrorMode (O)
       end
     end;
      

  2.   

    function GetDiskSerialNum(DiskName:char):longint;
    var
      TmpA,TmpE:Pchar;
      TmpB,TmpC,TmpD,TmpF:DWord;
      SerialNum:PDWord;
    begin
    TmpA:='';
       TmpB:=0;
       TmpC:=0;
       TmpD:=FS_UNICODE_STORED_ON_DISK ;
       TmpE:='';
       TmpF:=0;
       GetVolumeInformation(Pchar(DiskName+':\'),TmpA,TmpB,@SerialNum,TmpC,TmpD,TmpE,TmpF);
       Result :=DWord( SerialNum );
       if DWord(SerialNum)=0 then
       Try
        ChDir(DiskName+':\');
          Result := 1;
       except
       end;
    end;