function TfProzesse.WMIEnumProcesses(Computer, User, Password:
string): TPIArray;
function GetCompName:
string;
var
Buf :
array[0..MAX_COMPUTERNAME_LENGTH]
of Char;
Size : DWORD;
begin
Size := SizeOf(Buf);
if GetComputerName(Buf, Size)
then
Result := Buf
else
Result := '
';
end;
var
FComputer:
String;
FUser:
String;
FPassword:
String;
Services : ISWbemServices;
ObjectDefinition: ISWbemObject;
ObjectSet : SWbemObjectSet;
ObjectInstances: IEnumVariant;
WMIObject : ISWbemObject;
PropertySet : ISWbemPropertySet;
WMIProperty : ISWbemProperty;
TempObj : OleVariant;
ObjValue : Cardinal;
i : Integer;
resourcestring
rsWMIError = '
WMI-Fehler';
begin
if AnsiUpperCase(GetCompName) = AnsiUpperCase(Computer)
then
begin
FComputer := '
';
FUser := '
';
FPassword := '
';
end
else
begin
FComputer := Computer;
FUser := user;
FPassword := Password;
end;
i := 0;
//Locator := TSWbemLocator.Create(Nil);
try
try
Services := Locator.ConnectServer(FComputer, '
root\CIMV2',FUser, FPassword, '
', '
', 0,
nil);
if Services <>
nil then
begin
Services.Security_.Set_ImpersonationLevel(wbemImpersonationLevelImpersonate);
Services.Security_.Privileges.Add(wbemPrivilegeDebug, True);
ObjectDefinition := Services.Get('
Win32_Process',
wbemFlagUseAmendedQualifiers,
nil);
ObjectSet := ObjectDefinition.Instances_(0,
nil);
ObjectInstances := (ObjectSet._NewEnum)
as IEnumVariant;
while (ObjectInstances.Next(1, TempObj, ObjValue) = S_OK)
do
begin
//hier werden die Prozesse ausgelesen
end;
end;
finally
Services :=
nil;
end;
except
on e:
Exception do
raise e.Create(e.
message);
end;
end;