Solved

Windows Process and Service Listing

Posted on 2000-03-08
5
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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