Changeset 21 for trunk/UPhysDrive.pas


Ignore:
Timestamp:
Apr 2, 2016, 11:12:47 PM (9 years ago)
Author:
chronos
Message:
  • Added: Suport for physical drive enumeration under Windows.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22lib
        33CoolDisk.lps
         4CoolDisk.exe
  • trunk/UPhysDrive.pas

    r20 r21  
    66
    77uses
    8   Classes, SysUtils, Contnrs, UFindFile, UCommon;
     8  Classes, SysUtils, Contnrs, UFindFile, UCommon
     9  {$IFDEF Windows},ActiveX,ComObj,Variants
     10  {$ENDIF};
    911
    1012type
     
    2931    procedure LoadToStrings(Strings: TStrings);
    3032    procedure Detect;
     33  private
     34    {$IFDEF Windows}
     35    procedure GetWin32DiskDriveInfo;
     36    {$ENDIF}
    3137  end;
    3238
     
    109115  end;
    110116  {$ENDIF}
     117  {$IFDEF Windows}
     118  GetWin32DiskDriveInfo;
     119  {$ENDIF}
    111120  // Drive located using filename
    112121  NewDriveInfo := TDriveInfo.Create;
     
    120129end;
    121130
     131{$IFDEF Windows}
     132procedure TDriveList.GetWin32DiskDriveInfo;
     133const
     134  WbemUser = '';
     135  WbemPassword = '';
     136  WbemComputer = 'localhost';
     137  wbemFlagForwardOnly = $00000020;
     138var
     139  FSWbemLocator: OLEVariant;
     140  FWMIService: OLEVariant;
     141  FWbemObjectSet: OLEVariant;
     142  FWbemObject: OLEVariant;
     143  oEnum: IEnumvariant;
     144  OutVar: LongWord;
     145  NewDriveInfo: TDriveInfo;
     146begin;
     147  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
     148  FWMIService := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser,
     149    WbemPassword);
     150  FWbemObjectSet := FWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive',
     151    'WQL', wbemFlagForwardOnly);
     152  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
     153  while oEnum.Next(1, FWbemObject, OutVar) = 0 do begin
     154    NewDriveInfo := TDriveInfo.Create;
     155    NewDriveInfo.Kind := dkPhysical;
     156    NewDriveInfo.Model := FWbemObject.Properties_.Item('Caption').Value;
     157    //NewDriveInfo.Model := FWbemObject.Properties_.Item('Model').Value;
     158    NewDriveInfo.Size := FWbemObject.Properties_.Item('Size').Value;
     159    NewDriveInfo.SectorSize := 4096;
     160    NewDriveInfo.SectorCount := NewDriveInfo.Size div NewDriveInfo.SectorSize;
     161    NewDriveInfo.Path := FWbemObject.Properties_.Item('DeviceID').Value;
     162    Add(NewDriveInfo);
     163
     164    FWbemObject := Unassigned;
     165  end;
     166end;
     167{$ENDIF}
     168
     169
    122170end.
    123171
Note: See TracChangeset for help on using the changeset viewer.