Solved

Windows Process and Service Listing

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now