// 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 WMI_PhysicalDisk;
{$APPTYPE CONSOLE}
uses
// SysUtils, ActiveX, ComObj, Variants;
System.SysUtils,
Winapi.ActiveX,
System.Win.ComObj,
System.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.