Procedure TForm1.GetMemBanks();
var
// Objektreferenzen auf WMI
Services: ISWbemServices;
ObjectSet: ISWbemObjectSet;
SObject: ISWbemObject;
propSet : ISWbemPropertySet;
SProp: ISWbemProperty;
propEnum,
Enum: IEnumVariant;
tempObj: OleVariant;
Count,
Value: Cardinal;
ListItem: TListItem;
strValue:
String;
Column: TListColumn;
strQuery: WideString;
// Zähler für die Anzahl der Bänke
intBanks: Integer;
begin
// Initialisieren
intBanks := 1;
// sicherstellen, dass alle Anforderungen beendet wurden
SinkClasses.Cancel;
// mit Namespace verbinden
Services := Locator.ConnectServer('
', '
root\CIMV2', '
', '
', '
', '
', 0,
nil);
// Abfrage starten
ObjectSet := Services.ExecQuery('
SELECT Capacity FROM Win32_PhysicalMemory', '
WQL', wbemFlagReturnImmediately,
nil);
// Enumeration übernehmen
Enum := (ObjectSet._NewEnum)
as IEnumVariant;
// alle Einträge durchgehen
while (Enum.Next(1, tempObj, Value) = S_OK)
do
begin
SObject := IUnknown(tempObj)
as SWBemObject;
propSet := SObject.Properties_;
propEnum := (propSet._NewEnum)
as IEnumVariant;
while (propEnum.Next(1, tempObj, Value) = S_OK)
do
begin
SProp := IUnknown(tempObj)
as SWBemProperty;
strValue := '
';
if VarIsNull(SProp.Get_Value)
then
strValue := '
<empty>'
else
case SProp.CIMType
of
wbemCimtypeSint8, wbemCimtypeUint8, wbemCimtypeSint16, wbemCimtypeUint16,
wbemCimtypeSint32, wbemCimtypeUint32, wbemCimtypeSint64:
if VarIsArray(SProp.Get_Value)
then
begin
if VarArrayHighBound(SProp.Get_Value, 1) > 0
then
for Count := 1
to VarArrayHighBound(SProp.Get_Value, 1)
do
strValue := strValue + '
' + IntToStr(SProp.Get_Value[Count]);
end
else
strValue := IntToStr(SProp.Get_Value);
wbemCimtypeReal32, wbemCimtypeReal64:
strValue := FloatToStr(SProp.Get_Value);
wbemCimtypeBoolean:
if SProp.Get_Value
then
strValue := '
True'
else
strValue := '
False';
wbemCimtypeString, wbemCimtypeUint64:
if VarIsArray(SProp.Get_Value)
then
begin
if VarArrayHighBound(SProp.Get_Value, 1) > 0
then
for Count := 1
to VarArrayHighBound(SProp.Get_Value, 1)
do
strValue := strValue + '
' + SProp.Get_Value[Count];
end
else
strValue := SProp.Get_Value;
wbemCimtypeDatetime:
strValue := SProp.Get_Value;
wbemCimtypeReference:
begin
strValue := SProp.Get_Value;
// entfernt....
end;
wbemCimtypeChar16:
strValue := '
<16-bit character>';
wbemCimtypeObject:
strValue := '
<CIM Object>';
else
ShowMessage('
Unknown type');
end;
{case}
if sProp.
Name = '
Capacity'
then
begin
Memo1.Lines.Add('
MemBank' + IntToStr(intBanks) + '
: ' + strValue);
intBanks := intBanks +1;
end;
end;
{while propEnum}
end;
{while Enum}
strQuery := '
SELECT * FROM __InstanceCreationEvent within 5 WHERE TargetInstance' +
'
ISA "' + '
Win32_PhysicalMemory' + '
"';
Services.ExecNotificationQueryAsync(SinkClasses.DefaultInterface, strQuery, '
WQL', 0,
nil,
nil);
strQuery := '
SELECT * FROM __InstanceDeletionEvent within 5 WHERE TargetInstance' +
'
ISA "' + '
Win32_PhysicalMemory' + '
"';
Services.ExecNotificationQueryAsync(SinkClasses.DefaultInterface, strQuery, '
WQL', 0,
nil,
nil);
end;