this slowpoke moves

Get Physical Disk Information

Console Output :
program WMI_PhysicalDisk;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

function VarToInt(const AVariant: Variant): INT64;// integer;
begin Result := StrToIntDef(Trim(VarToStr(AVariant)), 0); end;

procedure  GetMSFT_PhysicalDiskInfo;
const
  WbemUser =''; WbemPassword =''; WbemComputer ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
begin;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\Microsoft\Windows\Storage', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM MSFT_PhysicalDisk','WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('AllocatedSize                       %d',[VarToInt(FWbemObject.AllocatedSize)]));// Uint64
    Writeln(Format('BusType                             %d',[VarToInt(FWbemObject.BusType)]));// Uint16
//    Writeln(Format('CannotPoolReason                    %d',[VarToInt(FWbemObject.CannotPoolReason)]));// Array of Uint16
    Writeln(Format('CanPool                             %s',[VarToStr(FWbemObject.CanPool)]));// Boolean
    Writeln(Format('Description                         %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('DeviceId                            %s',[VarToStr(FWbemObject.DeviceId)]));// String
    Writeln(Format('EnclosureNumber                     %d',[VarToInt(FWbemObject.EnclosureNumber)]));// Uint16
    Writeln(Format('FirmwareVersion                     %s',[VarToStr(FWbemObject.FirmwareVersion)]));// String
    Writeln(Format('FriendlyName                        %s',[VarToStr(FWbemObject.FriendlyName)]));// String
    Writeln(Format('HealthStatus                        %d',[VarToInt(FWbemObject.HealthStatus)]));// Uint16
    Writeln(Format('IsIndicationEnabled                 %s',[VarToStr(FWbemObject.IsIndicationEnabled)]));// Boolean
    Writeln(Format('IsPartial                           %s',[VarToStr(FWbemObject.IsPartial)]));// Boolean
    Writeln(Format('LogicalSectorSize                   %d',[VarToInt(FWbemObject.LogicalSectorSize)]));// Uint64
    Writeln(Format('Manufacturer                        %s',[VarToStr(FWbemObject.Manufacturer)]));// String
    Writeln(Format('MediaType                           %d',[VarToInt(FWbemObject.MediaType)]));// Uint16
    Writeln(Format('Model                               %s',[VarToStr(FWbemObject.Model)]));// String
    Writeln(Format('ObjectId                            %s',[VarToStr(FWbemObject.ObjectId)]));// String
//    Writeln(Format('OperationalStatus                   %d',[VarToInt(FWbemObject.OperationalStatus)]));// Array of Uint16
    Writeln(Format('OtherCannotPoolReasonDescription    %s',[VarToStr(FWbemObject.OtherCannotPoolReasonDescription)]));// String
    Writeln(Format('PartNumber                          %s',[VarToStr(FWbemObject.PartNumber)]));// String
    Writeln(Format('PassThroughClass                    %s',[VarToStr(FWbemObject.PassThroughClass)]));// String
    Writeln(Format('PassThroughIds                      %s',[VarToStr(FWbemObject.PassThroughIds)]));// String
    Writeln(Format('PassThroughNamespace                %s',[VarToStr(FWbemObject.PassThroughNamespace)]));// String
    Writeln(Format('PassThroughServer                   %s',[VarToStr(FWbemObject.PassThroughServer)]));// String
    Writeln(Format('PhysicalLocation                    %s',[VarToStr(FWbemObject.PhysicalLocation)]));// String
    Writeln(Format('PhysicalSectorSize                  %d',[VarToInt(FWbemObject.PhysicalSectorSize)]));// Uint64
    Writeln(Format('SerialNumber                        %s',[VarToStr(FWbemObject.SerialNumber)]));// String
    Writeln(Format('Size                                %d',[VarToInt(FWbemObject.Size)]));// Uint64
    Writeln(Format('SlotNumber                          %d',[VarToInt(FWbemObject.SlotNumber)]));// Uint16
    Writeln(Format('SoftwareVersion                     %s',[VarToStr(FWbemObject.SoftwareVersion)]));// String
    Writeln(Format('SpindleSpeed                        %d',[VarToInt(FWbemObject.SpindleSpeed)]));// Uint32
//    Writeln(Format('SupportedUsages                     %d',[VarToInt(FWbemObject.SupportedUsages)]));// Array of Uint16
    Writeln(Format('UniqueId                            %s',[VarToStr(FWbemObject.UniqueId)]));// String
    Writeln(Format('Usage                               %d',[VarToInt(FWbemObject.Usage)]));// Uint16

    Writeln('-------------------------------------------------------------------');
    FWbemObject:=Unassigned;
  end;
end;

begin
 try
    CoInitialize(nil);
    try
      GetMSFT_PhysicalDiskInfo;
    finally
      CoUninitialize;
    end;
 except
    on E:EOleException do
        Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
    on E:Exception do
        Writeln(E.Classname, ':', E.Message);
 end;
 Writeln('Press Enter to exit');
 Readln;
end.
Same Code for GUI :
uses ActiveX, ComObj

//

function VarToInt(const AVariant: Variant): INT64;
begin
    Result := StrToIntDef(Trim(VarToStr(AVariant)), 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  WbemUser =''; WbemPassword =''; WbemComputer ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService   : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject   : OLEVariant;
  oEnum         : IEnumvariant;
  iValue        : LongWord;
  i             : integer;
begin
  i := 0;
  FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  FWMIService   := FSWbemLocator.ConnectServer(WbemComputer,
                   'root\Microsoft\Windows\Storage', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM MSFT_PhysicalDisk',
                   'WQL',wbemFlagForwardOnly);
  oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;

  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
  i := i + 1;
  Memo1.Lines.Add('<-- ' + 'Disk : ' + IntToStr(i) + ' ---------->');
  Memo1.Lines.Add(Format('AllocatedSize ----------: %d',[VarToInt(FWbemObject.AllocatedSize)]));
  Memo1.Lines.Add(Format('BusType ----------------: %d',[VarToInt(FWbemObject.BusType)]));
  //Memo1.Lines.Add(Format('CannotPoolReason   %d',[VarToInt(FWbemObject.CannotPoolReason)]));
  Memo1.Lines.Add(Format('CanPool ----------------: %s',[VarToStr(FWbemObject.CanPool)]));
  Memo1.Lines.Add(Format('Description ------------: %s',[VarToStr(FWbemObject.Description)]));
  Memo1.Lines.Add(Format('DeviceID ---------------: %s',[VarToStr(FWbemObject.DeviceId)]));
  Memo1.Lines.Add(Format('EnclosureNumber --------: %d',[VarToInt(FWbemObject.EnclosureNumber)]));
  Memo1.Lines.Add(Format('FirmwareVersion --------: %s',[VarToStr(FWbemObject.FirmwareVersion)]));
  Memo1.Lines.Add(Format('FriendlyName -----------: %s',[VarToStr(FWbemObject.FriendlyName)]));
  Memo1.Lines.Add(Format('HealthStatus -----------: %d',[VarToInt(FWbemObject.HealthStatus)]));
  Memo1.Lines.Add(Format('IsIndicationEnabled ----: %s',[VarToStr(FWbemObject.IsIndicationEnabled)]));
  Memo1.Lines.Add(Format('IsPartial --------------: %s',[VarToStr(FWbemObject.IsPartial)]));
  Memo1.Lines.Add(Format('LogicalSectorSize ------: %d',[VarToInt(FWbemObject.LogicalSectorSize)]));
  Memo1.Lines.Add(Format('Manufacturer -----------: %s',[VarToStr(FWbemObject.Manufacturer)]));
  Memo1.Lines.Add(Format('MediaType --------------: %d',[VarToInt(FWbemObject.MediaType)]));
  Memo1.Lines.Add(Format('Model ------------------: %s',[VarToStr(FWbemObject.Model)]));
  Memo1.Lines.Add(Format('ObjectId ---------------: %s',[VarToStr(FWbemObject.ObjectId)]));
  //Memo1.Lines.Add(Format('OperationalStatus   %d',[VarToInt(FWbemObject.OperationalStatus)]));
  Memo1.Lines.Add(Format('PoolReasonDescription --: %s',[VarToStr(FWbemObject.OtherCannotPoolReasonDescription)]));
  Memo1.Lines.Add(Format('PartNumber -------------: %s',[VarToStr(FWbemObject.PartNumber)]));
  Memo1.Lines.Add(Format('PassThroughClass -------: %s',[VarToStr(FWbemObject.PassThroughClass)]));
  Memo1.Lines.Add(Format('PassThroughIds ---------: %s',[VarToStr(FWbemObject.PassThroughIds)]));
  Memo1.Lines.Add(Format('PassThroughNamespace ---: %s',[VarToStr(FWbemObject.PassThroughNamespace)]));
  Memo1.Lines.Add(Format('PassThroughServer ------: %s',[VarToStr(FWbemObject.PassThroughServer)]));
  Memo1.Lines.Add(Format('PhysicalLocation -------: %s',[VarToStr(FWbemObject.PhysicalLocation)]));
  Memo1.Lines.Add(Format('PhysicalSectorSize -----: %d',[VarToInt(FWbemObject.PhysicalSectorSize)]));
  Memo1.Lines.Add(Format('SerialNumber -----------: %s',[VarToStr(FWbemObject.SerialNumber)]));
  Memo1.Lines.Add(Format('Size -------------------: %d',[VarToInt(FWbemObject.Size)]));
  Memo1.Lines.Add(Format('SlotNumber -------------: %d',[VarToInt(FWbemObject.SlotNumber)]));
  Memo1.Lines.Add(Format('SoftwareVersion --------: %s',[VarToStr(FWbemObject.SoftwareVersion)]));
  Memo1.Lines.Add(Format('SpindleSpeed -----------: %d',[VarToInt(FWbemObject.SpindleSpeed)]));
  //Label32.Caption := (Format('SupportedUsages       %d',[VarToInt(FWbemObject.SupportedUsages)]));
  Memo1.Lines.Add(Format('UniqueId ---------------: %s',[VarToStr(FWbemObject.UniqueId)]));
  Memo1.Lines.Add(Format('Usage ------------------: %d',[VarToInt(FWbemObject.Usage)]));
  Memo1.Lines.Add('<-- ' + 'End Disk : ' + IntToStr(i) + ' ------>');
  Memo1.Lines.Add('');
  FWbemObject:=Unassigned;
  end;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate