AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

[WMI] Prozesse remote auflisten

Ein Thema von Luckie · begonnen am 15. Jan 2005 · letzter Beitrag vom 15. Jan 2005
 
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

[WMI] Prozesse remote auflisten

  Alt 15. Jan 2005, 07:01
Ich benutze folgenden Code, um mir die Prozesses des Computers aufzulisten per WMI:
Delphi-Quellcode:
uses
  WbemScripting_TLB, ActiveX;

type
  TProcesInformation = packed record
    Name: string;
    Path: string;
    ProcID: DWORD;
    ParentProcID: DWORD;
    SessionID: DWORD;
    ThreadCount: DWORD;
    Priority: DWORD;
  end;

type
  TPIArray = array of TProcesInformation;

const
  WMI_HOST_COMPUTER = '.';
  WMI_SYSTEM_NAMESPACE = 'root\CIMV2';
  WMI_CLASS_NIC = 'Win32_Process';
  WMI_ATTRIB_CAPTION = 'Name';
  WMI_ATTRIB_PATH = 'ExecutablePath';
  WMI_ATTRIB_PROCID = 'ProcessID';
  WMI_ATTRIB_PARENT_PROCID = 'ParentProcessId';
  WMI_ATTRIB_SESSIONID = 'SessionID';
  WMI_ATTRIB_THREAD_CNT = 'ThreadCount';
  WMI_ATTRIB_PRIORITY = 'Priority';

function WMIEnumProcesses(Computer, User, Password: String): TPIArray;
var
  Locator : ISWbemLocator;
  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
  i := 0;
  Locator := CoSWbemLocator.CreateRemote(Computer);
  try
    try
      Services := Locator.ConnectServer(Computer, WMI_SYSTEM_NAMESPACE,
        User, Password, '', '', 0, nil);
      if Services <> nil then
      begin
        ObjectDefinition := Services.Get(WMI_CLASS_NIC,
          wbemFlagUseAmendedQualifiers, nil);
        ObjectSet := ObjectDefinition.Instances_(0, nil);
        ObjectInstances := (ObjectSet._NewEnum) as IEnumVariant;
        while (ObjectInstances.Next(1, TempObj, ObjValue) = S_OK) do
        begin
          WMIObject := IUnknown(TempObj) as SWBemObject;
          PropertySet := WMIObject.Properties_;

          setlength(result, length(result) + 1);
          WMIProperty := PropertySet.Item(WMI_ATTRIB_CAPTION, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].Name := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_PATH, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].Path := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_PROCID, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].ProcID := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_PARENT_PROCID, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].ParentProcID := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_SESSIONID, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].SessionID := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_THREAD_CNT, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].ThreadCount := WMIProperty.Get_Value;
          WMIProperty := PropertySet.Item(WMI_ATTRIB_PRIORITY, 0);
          if not VarIsNull(WMIProperty.Get_Value) then
            result[i].Priority := WMIProperty.Get_Value;
          Inc(i);
        end;
      end;
    finally
      Locator := nil;
      Services := nil;
    end;
  except
    on e: Exception do
      raise e.Create(e.message);
  end;
end;
Folgende Probleme:
  1. Von Windows2000 nacch Windows XP Home bekomme ich einen "Zugriff verweigert".
  2. Von XP Home nach Windows2000 bekomme ich "Der RPC-Server ist nicht verfügbar":
  3. Rufe ich das ganze mit dem loaklen Rechnernamen, einem lokalen Benutzer und Passwort auf, bekomme ich eine "Zugriffsverletzung bei Adresse 00000000. Lesen von Adresse 00000000."
Ich hänge die Exe mal an. Es wäre nett wenn ihr das mal testen könntet, so fern ihr ein Netzwerk zur Verfügung habt.
Angehängte Dateien
Dateityp: exe project1_152.exe (190,0 KB, 33x aufgerufen)
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:25 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz