Einzelnen Beitrag anzeigen

Delphi-Delphin

Registriert seit: 23. Feb 2010
10 Beiträge
 
FreePascal / Lazarus
 
#10

AW: Direktes lesen auf dem physischen Datenträger

  Alt 18. Jun 2018, 12:26
Vielen Dank, für deine großartige Hilfe.

Deine Exe liefert sogar noch viel mehr Informationen, als ich brauche.

Mit dem Code lässt sich also sehr gut was anfangen. Der verlinkte Code ließ sich auch fehlerfrei im Lazarus kompilieren.

Edit: Hab auch noch einen Fehler im Code gefunden.
Bei Writeln(Format('Size %d',[VarToInt(FWbemObject.Size)]));// Uint64 kommt es zu einem Überlauf, da die Funktion selbst nur einen 32 Bit Integer verwendet.

Angepasst:
Delphi-Quellcode:
//-----------------------------------------------------------------------------------------------------
// This code was generated by the Wmi Delphi Code Creator http://theroadtodelphi.wordpress.com
// Version: 1.8.3.0
// LIABILITY DISCLAIMER
// THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
// YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
// DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
//----------------------------------------------------------------------------------------------------
program GetWMI_DiskDriveInfo;

{$APPTYPE CONSOLE}

uses
 // SysUtils, ActiveX, ComObj, Variants;
  SysUtils,
  ActiveX,
  ComObj,
  Variants;

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

function VarToQWord(const AVariant: Variant): QWord;
begin Result := StrToQWordDef(Trim(VarToStr(AVariant)), 0); end;

// Die Klasse "Win32_DiskDrive" stellt ein physikalisches Laufwerk eines Computer dar,
// auf dem das Win32-Betriebssystem ausgeführt wird. Jede Schnittstelle zu einem physikalischen
// Win32-Laufwerk ist ein Mitglied dieser Klasse. Die Funktionen des Laufwerks in diesem
// Objekt entsprechen den logischen Laufwerkmerkmalen. Ein Objekt, das auf einem anderen logischen Gerät basiert,
// ist kein Mitglied dieser Klasse.
// Beispiel: IDE-Festplatte.

procedure GetWin32_DiskDriveInfo;
const
  WbemUser ='';
  WbemPassword ='';
  WbemComputer ='localhost';
  wbemFlagForwardOnly = $00000020;
var
  FSWbemLocator : OLEVariant;
  FWMIService : OLEVariant;
  FWbemObjectSet: OLEVariant;
  FWbemObject : OLEVariant;
  oEnum : IEnumvariant;
  iValue : LongWord;
  i: integer;
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;
  i:=0;
  while oEnum.Next(1, FWbemObject, iValue) = 0 do
  begin
    Writeln(Format('*** DISK %d ***',[i]));
    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',[VarToInt(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',[VarToInt(FWbemObject.MaxBlockSize)]));// Uint64
    Writeln(Format('MaxMediaSize %d',[VarToInt(FWbemObject.MaxMediaSize)]));// Uint64
    Writeln(Format('MediaLoaded %s',[VarToStr(FWbemObject.MediaLoaded)]));// Boolean
    Writeln(Format('MediaType %s',[VarToStr(FWbemObject.MediaType)]));// String
    Writeln(Format('MinBlockSize %d',[VarToInt(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 Byte = %f GB',[VarToQWord(FWbemObject.Size),VarToQWord(FWbemObject.Size)/(1000000000)]));// 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',[VarToInt(FWbemObject.TotalCylinders)]));// Uint64
    Writeln(Format('TotalHeads %d',[VarToInt(FWbemObject.TotalHeads)]));// Uint32
    Writeln(Format('TotalSectors %d',[VarToInt(FWbemObject.TotalSectors)]));// Uint64
    Writeln(Format('TotalTracks %d',[VarToInt(FWbemObject.TotalTracks)]));// Uint64
    Writeln(Format('TracksPerCylinder %d',[VarToInt(FWbemObject.TracksPerCylinder)]));// Uint32

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

    inc(i);
  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.
Künstliche Intelligenz ist gar nichts - verglichen mit natürlicher Dummheit

Geändert von Delphi-Delphin (18. Jun 2018 um 13:09 Uhr)
  Mit Zitat antworten Zitat