Solved

Windows Process and Service Listing

Posted on 2000-03-08
5
170 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 172
Multiple image collision 13 102
Convert MS Word document to a PDF file 9 130
Breakpoint doesn't stop in my variable 3 45
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

736 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