Solved

Windows Process and Service Listing

Posted on 2000-03-08
5
164 Views
Last Modified: 2010-05-18
How can I retrieve a listing of the Windows (NT, 9.x, 2000) services and processes, which are running at the given time?
0
Comment
Question by:kwerling
  • 4
5 Comments
 
LVL 1

Accepted Solution

by:
XAN earned 100 total points
ID: 2597069
from www.madshi.com :
( or http://nettrash.com/users/madshi/)

function GetProcessList(threadsToo: boolean = false;windowsToo: boolean =
  false): TProcessList;
var
  c1: cardinal;
  i1, i2, i3, i4: integer;
  tl: TThreadList;
  pe: TProcessEntry32;
begin
  result := nil;
  if GetOperatingSystem in [osWin95, osWin95osr2, osWin98, osWinNT5] then
  begin
    if not TestToolhelpFunctions then
    begin
      MessageBox(0, 'Toolhelp functions not available.', 'Error...', 0);
      exit;
    end;
    c1 := CreateToolHelp32Snapshot(TH32CS_SnapProcess, 0);
    try
      i1 := 0;
      pe.dwSize := sizeOf(pe);
      if Process32First(c1, pe) then
        repeat
          SetLength(result, i1 + 1);
          result[i1].pid := pe.th32ProcessID;
          result[i1].name := pe.szExeFile;
          result[i1].exeType := GetExeType(result[i1].name);
          inc(i1);
        until not Process32Next(c1, pe);
    finally CloseHandle(c1)
    end;
    if threadsToo then tl := GetThreadList(0, windowsToo);
  end
  else
    if GetOperatingSystem in [osWinNT3, osWinNT4, osWinNT4SP4] then
      if (threadsToo and (not NT4_EnumProcessesAndThreads(@result, @tl,
        windowsToo))) or
        ((not threadsToo) and (not NT4_EnumProcessesAndThreads(@result, nil,
          false))) then
        MessageBox(0, 'Error reading Performace Data.', 'Error...', 0);
  i4 := high(tl);
  if i4 > 0 then
    for i1 := 0 to i4 do
      for i2 := high(result) downto 0 do
        if tl[i1].pid = result[i2].pid then
        begin
          i3 := length(result[i2].threads);
          setLength(result[i2].threads, i3 + 1);
          result[i2].threads[i3] := tl[i1];
        end;
end;


0
 

Author Comment

by:kwerling
ID: 2601549
Hi,


Let me start with saying thanks!

This seems to be the right track.

I downloaded the unit on the above mentioned web site.

When I compile, my compiler complains about:  

      NT4_EnumProcessesAndThreads

                 and

        TestToolhelpFunctions

It does not know these sybmbols - Any idea?

I compiled the code with commenting the appropriate bits of code out, but I just got an empty list as result.

So obviously I am doing something wrong here!
0
 

Author Comment

by:kwerling
ID: 2601561
Hi,


Let me start with saying thanks!

This seems to be the right track.

I downloaded the unit on the above mentioned web site.

When I compile, my compiler complains about:  

      NT4_EnumProcessesAndThreads

                 and

        TestToolhelpFunctions

It does not know these sybmbols - Any idea?

I compiled the code with commenting the appropriate bits of code out, but I just got an empty list as result.

So obviously I am doing something wrong here!
0
 

Author Comment

by:kwerling
ID: 2601609
All my fault.

The solution is terrific! It does exactly what I want it to do!!

Sorry for the confusion before!
I am very satisfied!

Kristof
0
 

Author Comment

by:kwerling
ID: 2601613
Meets exactly my needs.

Thanks a lot!

Kristof
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question