function QueryWMI(
const QueryClass, QueryProperty:
String; AStrings: TStrings): Boolean;
var
Locator: ISWbemLocator;
Services: ISWbemServices;
ObjectSet: ISWbemObjectSet;
WMIObject: ISWbemObject;
WMIProperty: ISWbemProperty;
Enum: IEnumVariant;
ObjValue: Cardinal;
TempObj: OleVariant;
begin
Result := FALSE;
try
Locator := CoSWbemLocator.Create;
try
Services := Locator.ConnectServer('
', '
root\cimv2', '
', '
', '
','
', 0,
NIL);
if Assigned(Services)
then begin
Services.Security_.ImpersonationLevel := 3;
ObjectSet := Services.ExecQuery('
SELECT * FROM '+QueryClass,
'
WQL',
wbemFlagForwardOnly
or wbemFlagReturnWhenComplete,
NIL);
Enum := (ObjectSet._NewEnum)
as IEnumVariant;
while (Enum.Next(1, TempObj, ObjValue) = S_OK)
do begin
try
WMIObject := IUnknown(TempObj)
as ISWBemObject;
except
WMIObject :=
NIL;
end;
TempObj := Unassigned;
// Interface in TempObj freigeben
if Assigned(WMIObject)
then begin
WMIProperty := WMIObject.Properties_.Item(QueryProperty, 0);
if (
NOT VarIsNull(WMIProperty.Get_Value))
then
AStrings.Add(Trim(WMIProperty.Get_Value));
end;
end;
Result := TRUE;
end;
finally
Services :=
NIL;
Locator :=
NIL;
end;
except // Exceptions fangen (Wenn WMI nicht verfügbar/installiert ist, gibt´s eine!)
Result := FALSE;
end;
end;
procedure TfrmSystemInfo.Button1Click(Sender: TObject);
begin
QueryWMI('
Win32_VideoController','
Caption',Systemauswertung.Lines);
end;