Solved

Windows Process and Service Listing

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

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

617 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