Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Direktes lesen auf dem physischen Datenträger

  Alt 18. Jun 2018, 13:22
Bei Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64 kommt es zu einem Überlauf, da die Funktion selbst nur einen 32 Bit Integer verwendet.
Es freut mich wenn es das macht was Du wolltest, Danke für Fehler-Report!
Delphi-Quellcode:
function VarToInt64(const AVariant: Variant): Int64;
begin Result := StrToInt64Def(Trim(VarToStr(AVariant)), 0); end;
    Writeln(Format('Size %d Byte = %f GB',[VarToInt64(FWbemObject.Size),VarToInt64(FWbemObject.Size)/(1000*1000*1000)]));// Uint64 Habe es mit Delphi so abgeändert, vielen Dank!

edit
Delphi-Quellcode:
program GetWMI_DiskDriveInfo;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

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

function VarToInt64(const AVariant: Variant): Int64;
begin Result := StrToInt64Def(Trim(VarToStr(AVariant)), 0); end;

procedure GetWin32_DiskDriveInfo;
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\CIMV2', WbemUser, WbemPassword);
  FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_DiskDrive','WQL',wbemFlagForwardOnly);
  oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('Availability %d',[VarToInt(FWbemObject.Availability)]));// Uint16
    Writeln(Format('BytesPerSector %d',[VarToInt(FWbemObject.BytesPerSector)]));// Uint32
// Writeln(Format('Capabilities %d',[VarToInt(FWbemObject.Capabilities)]));// Array of Uint16
// Writeln(Format('CapabilityDescriptions %s',[VarToStr(FWbemObject.CapabilityDescriptions)]));// Array of VarToStr
    Writeln(Format('Caption %s',[VarToStr(FWbemObject.Caption)]));// VarToStr
    Writeln(Format('CompressionMethod %s',[VarToStr(FWbemObject.CompressionMethod)]));// String
    Writeln(Format('ConfigManagerErrorCode %d',[VarToInt(FWbemObject.ConfigManagerErrorCode)]));// Uint32
    Writeln(Format('ConfigManagerUserConfig %s',[VarToStr(FWbemObject.ConfigManagerUserConfig)]));// Boolean
    Writeln(Format('CreationClassName %s',[VarToStr(FWbemObject.CreationClassName)]));// String
    Writeln(Format('DefaultBlockSize %d',[VarToInt64(FWbemObject.DefaultBlockSize)]));// Uint64
    Writeln(Format('Description %s',[VarToStr(FWbemObject.Description)]));// String
    Writeln(Format('DeviceID %s',[VarToStr(FWbemObject.DeviceID)]));// String
    Writeln(Format('ErrorCleared %s',[VarToStr(FWbemObject.ErrorCleared)]));// Boolean
    Writeln(Format('ErrorDescription %s',[VarToStr(FWbemObject.ErrorDescription)]));// String
    Writeln(Format('ErrorMethodology %s',[VarToStr(FWbemObject.ErrorMethodology)]));// String
    Writeln(Format('FirmwareRevision %s',[VarToStr(FWbemObject.FirmwareRevision)]));// String
    Writeln(Format('Index %d',[VarToInt(FWbemObject.Index)]));// Uint32
    Writeln(Format('InstallDate %s',[VarToStr(FWbemObject.InstallDate)]));// Datetime
    Writeln(Format('InterfaceType %s',[VarToStr(FWbemObject.InterfaceType)]));// String
    Writeln(Format('LastErrorCode %d',[VarToInt(FWbemObject.LastErrorCode)]));// Uint32
    Writeln(Format('Manufacturer %s',[VarToStr(FWbemObject.Manufacturer)]));// String
    Writeln(Format('MaxBlockSize %d',[VarToInt64(FWbemObject.MaxBlockSize)]));// Uint64
    Writeln(Format('MaxMediaSize %d',[VarToInt64(FWbemObject.MaxMediaSize)]));// Uint64
    Writeln(Format('MediaLoaded %s',[VarToStr(FWbemObject.MediaLoaded)]));// Boolean
    Writeln(Format('MediaType %s',[VarToStr(FWbemObject.MediaType)]));// String
    Writeln(Format('MinBlockSize %d',[VarToInt64(FWbemObject.MinBlockSize)]));// Uint64
    Writeln(Format('Model %s',[VarToStr(FWbemObject.Model)]));// String
    Writeln(Format('Name %s',[VarToStr(FWbemObject.Name)]));// String
    Writeln(Format('NeedsCleaning %s',[VarToStr(FWbemObject.NeedsCleaning)]));// Boolean
    Writeln(Format('NumberOfMediaSupported %d',[VarToInt(FWbemObject.NumberOfMediaSupported)]));// Uint32
    Writeln(Format('Partitions %d',[VarToInt(FWbemObject.Partitions)]));// Uint32
    Writeln(Format('PNPDeviceID %s',[VarToStr(FWbemObject.PNPDeviceID)]));// String
    Writeln(Format('PowerManagementCapabilities %d',[VarToInt(FWbemObject.PowerManagementCapabilities)]));// Array of Uint16
    Writeln(Format('PowerManagementSupported %s',[VarToStr(FWbemObject.PowerManagementSupported)]));// Boolean
    Writeln(Format('SCSIBus %d',[VarToInt(FWbemObject.SCSIBus)]));// Uint32
    Writeln(Format('SCSILogicalUnit %d',[VarToInt(FWbemObject.SCSILogicalUnit)]));// Uint16
    Writeln(Format('SCSIPort %d',[VarToInt(FWbemObject.SCSIPort)]));// Uint16
    Writeln(Format('SCSITargetId %d',[VarToInt(FWbemObject.SCSITargetId)]));// Uint16
    Writeln(Format('SectorsPerTrack %d',[VarToInt(FWbemObject.SectorsPerTrack)]));// Uint32
    Writeln(Format('SerialNumber %s',[TRIM(VarToStr(FWbemObject.SerialNumber))]));// String
    Writeln(Format('Signature %d',[VarToInt(FWbemObject.Signature)]));// Uint32
// Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64
    Writeln(Format('Size %d Byte = %f GB',[VarToInt64(FWbemObject.Size),VarToInt64(FWbemObject.Size)/(1000*1000*1000)]));// Uint64
    Writeln(Format('Status %s',[VarToStr(FWbemObject.Status)]));// String
    Writeln(Format('StatusInfo %d',[VarToInt(FWbemObject.StatusInfo)]));// Uint16
    Writeln(Format('SystemCreationClassName %s',[VarToStr(FWbemObject.SystemCreationClassName)]));// String
    Writeln(Format('SystemName %s',[VarToStr(FWbemObject.SystemName)]));// String
    Writeln(Format('TotalCylinders %d',[VarToInt64(FWbemObject.TotalCylinders)]));// Uint64
    Writeln(Format('TotalHeads %d',[VarToInt(FWbemObject.TotalHeads)]));// Uint32
    Writeln(Format('TotalSectors %d',[VarToInt64(FWbemObject.TotalSectors)]));// Uint64
    Writeln(Format('TotalTracks %d',[VarToInt64(FWbemObject.TotalTracks)]));// Uint64
    Writeln(Format('TracksPerCylinder %d',[VarToInt(FWbemObject.TracksPerCylinder)]));// Uint32
    Writeln('----------------------------------------------------------------------------');
    FWbemObject:=Unassigned;
  end;
end;


begin
 try
    CoInitialize(nil);
    try
      GetWin32_DiskDriveInfo;
    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.
Nun haben alle Int64 Typen ihren Ansprechpartner
Gruß vom KodeZwerg

Geändert von KodeZwerg (18. Jun 2018 um 13:58 Uhr)
  Mit Zitat antworten Zitat