{$APPTYPE CONSOLE}
program Project1;
uses Windows, SysUtils, Variants, ComObj, ActiveX;
function GetDynaNameProperty(const Source: Variant;
const PropertyName: AnsiString): Variant;
var
Desc: TCallDesc;
begin
ZeroMemory(@Desc, SizeOf(Desc));
Desc.CallType := DISPATCH_PROPERTYGET;
Move(PropertyName[1], Desc.ArgTypes[0], Length(PropertyName));
VarDispProc(@Result, Source, @Desc, nil);
end;
procedure WriteWMIQuery(const FWMIService: OleVariant;
const Query: WideString; const PropNames: array of string);
const
WBEM_FLAG_FORWARD_ONLY = $20;
WBEM_RETURN_IMMEDIATELY = $10;
var
FWbemCollection: OleVariant;
Enum: IEnumvariant;
iValue: ULONG;
FWbemObject: OleVariant;
i, k: Integer;
Prop: Variant;
begin
Writeln('[', Query, ']');
FWbemCollection := FWMIService.ExecQuery(Query, 'WQL',
WBEM_FLAG_FORWARD_ONLY or WBEM_RETURN_IMMEDIATELY);
Enum := IUnknown(FWbemCollection._NewEnum) as IEnumVariant;
while Enum.Next(1, FWbemObject, iValue) = 0 do
begin
for i := Low(PropNames) to High(PropNames) do
begin
Prop := GetDynaNameProperty(FWbemObject, PropNames[i]);
if VarIsArray(Prop) then
for k := VarArrayLowBound(Prop, 1) to VarArrayHighBound(Prop, 1) do
Writeln(PropNames[i], '[', k, ']: ', Prop[k])
else
Writeln(PropNames[i], ': ', Prop);
end;
Writeln('');
FWbemObject:=Unassigned;
end;
end;
const
WbemUser = '';
WbemPassword = '';
WbemComputer = 'localhost';
var
SWbemLocator: OleVariant;
WMIService: OleVariant;
begin
NullStrictConvert := False;
SWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WMIService := SWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
WriteWMIQuery(WMIService, 'select * from Win32_ComputerSystemProduct',
['Vendor', 'Version']);
WriteWMIQuery(WMIService, 'select * from Win32_ComputerSystem',
['Name', 'Manufacturer', 'PrimaryOwnerName', 'SystemType']);
WriteWMIQuery(WMIService, 'select * from Win32_OperatingSystem',
['Caption', 'Version', 'OSArchitecture', 'SerialNumber', 'BootDevice', 'TotalVisibleMemorySize']);
WriteWMIQuery(WMIService, 'select * from Win32_NetworkAdapterConfiguration where IPEnabled=True',
['Caption', 'MACAddress', 'IPAddress']);
Readln;
end.