王宏健的专栏 ---- 健康快乐

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
希望能得到这样的结果  
 
磁盘  1  的分区  1  :  C  
磁盘  1  的分区  2  :  D  
磁盘  1  的分区  3  :  E  
磁盘  1  的分区  4  :  F  
磁盘  2  的分区  1  :  G  
磁盘  2  的分区  2  :  I  
磁盘  2  的分区  3  :  J  
磁盘  2  的分区  4  :  K  
===================================================
就是这样了,GetVolumeInfo('C').DiskNumber结果就是所在的物理磁盘ID  
 
需要JEDI的Win32支持库才能编译!  
 
function  GetVolumeInfo(DriverLetter:  Char):  TDiskExtent;  
var  
   hVolume:  THandle;  
   DiskExtents:  PVolumeDiskExtents;  
   dwOutBytes:  Cardinal;  
begin  
   with  Result  do  
       begin  
           DiskNumber  :=  0;  
           StartingOffset.QuadPart  :=  0;  
           ExtentLength.QuadPart  :=  0;  
       end;  
   hVolume  :=  CreateFile(PChar('\\.\'+DriverLetter+':'),  GENERIC_READ  or  GENERIC_WRITE,  
                                                 FILE_SHARE_READ  or  FILE_SHARE_WRITE,  nil,  OPEN_EXISTING,  0,  0);  
   if  hVolume  <  1  then  Exit;  
   DiskExtents  :=  AllocMem(Max_Path);  
   if  DeviceIoControl(hVolume,  
                               IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,  
                               nil,  0,  
                               DiskExtents,  Max_Path,  
                               dwOutBytes,  nil)  then  
         begin  
             if  DiskExtents^.NumberOfDiskExtents  >  0  then  
                   Result  :=  DiskExtents^.Extents[0];  
         end;  
   FreeMem(DiskExtents);  
   CloseHandle(hVolume);  
end;
posted on 2005-05-13 10:16  LuckyJan  阅读(577)  评论(0)    收藏  举报