Working with listing running Processes

to make it fairely strait forward (the CTRL+ALT+DEL) in windows brings up the all to familiar list of running programs I want to for the most part recreate this.

the first thing I need to do is to be able to list the programs that are running. Once I have the process name I can close the app. can some one give me a nice clean way to get a list of all running applications.

by the way this is for a Win NT machine so unregistered proccesses shouldn't be a problem like 9x if you know of a possible conflict comments are more than welcome.

With it you can also enumerate all processes in all systems, but you have to care about closing yourself. You can use PostMessage(processMainWindow, WM_CLOSE, 0, 0), PostThreadMessage(processMainThreadID, WM_QUIT, 0, 0) or TerminateProcess(processHandle, 0) to achieve similar results to the examples above.

let me have a day or so to look everything over and see if I can pick out what I need I prefer strait code makes it easier to apply to other programs later down the road and makes it easier to modify to meet my needs specificaly. but I am checking int the unumstuff for now. until then
thank you for your help and other comments are still welcome.

after looking over enum I am almost possitive that I should be able to pull what I need I only require a little help in converting a few results into information that I am familiar with so that I may view the processes in a list. are you willing to do this?

>if you have D4-6 and want to have it easy, you can use my >package "madKernel" (free for non-commercial
>usage). With it you can do things like this:

>// show all running processes:
>with Processes do
> for i := 0 to ItemCount - 1 do
> ShowMessage(Items[i1].ExeFile);

So dont think Im competing for points or anything, I just thought that BloodLine might learn something from seeing some code to play with.....Ive found the best way to learn is playing around. My 2 pence worth :)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

However: Your code needs psApi.dll to run under NT4 and psApi.dll is not included in every NT installation. So you have to distribute this dll with your application (that is allowed) if you're using that code. My code (both enumStuff and madKernel) works without needing that psApi.dll.

thank you both I am attempting to empliment the code the best I can and smurff I appreaciate the code to me it seems a little more user friendly to apply in the future. and it also seems tailored more towards what I actualy need there for I am most likely going to award you the points but I need to examine witch works with my problem most I believe that I would like to give you both points for your help I have points to blow god bless the accumulating points thing and I usualy only use exchange for maybe one major project a year. so this is what I will do one of you may have the points listed and I will set another question out for the other I will allow you to decide who shall get wich either way you will both make out with 300 points.

I will also soon be posting another question specificaly on killing applications and will be giving more points for that also so if you want easy points keep the eye out for it. does this sound like an agreable arangement?

I am how ever having a problem with getting applications to die do you to think this may be the way I am doing it and the code works well or should I look for a better method of closing applications?

Please note, that with Smurff's code you need to distribute psApi.dll with your application. Just wanted to make that clear, in case you missed it...

>> I am how ever having a problem with getting applications to die

There are several ways of killing apps. I've explained that in my first comment (see the last paragraph). In fact the killing code in Smurff's code is not a good one. SendMessage(WM_CLOSE) fails *very* often. Just exchange "SendMessage" with "PostMessage", then it will run a lot better. Besides from the WM_CLOSE killing there are at least 2 other ways, see my first comment.

>Please note, that with Smurff's code you need to >distribute psApi.dll with your application. Just wanted
>to make that clear, in case you missed it...

I havent specifically installed the .dll and I have it. Ive installed Service pack 6, IE 5.5, Office2k, Delphi5Ent, PSP7... I know its not a default installation dll so I can assume that its a popular dll.
It's documentation resides under "Windows Base Services",
"Windows NT Features", "Process Status Helper" and every PC in my company seems to have it....The dll itself is only 18k so if you did need to distribute it then its not that much of an issue (i think anyway). I am still saying your components are very good though.

Bloodline,
Wow. thanks I wasnt expecting points. How are you trying to kill it? was it the procedure I put? if so then I think theres probably a better way. I didnt know about the PostMessage like what Madshi said so sorry about that.
I also noticed that the proc. I showed you closes apps by the caption name in the titlebar, but the list produces the .exe name. The EnumProcesses does produce an array or process Id`s. Its probably better killing them by that. I`ll have a look for you(or does Madshi already know?)

If I remember right it's included in SP6 or something like that. But if you don't want your application to require SP6, you would nevertheless have to distribute psApi.dll with your app. No big thing, of course. Just worth a mention...

>> I also noticed that the proc. I showed you closes apps by the caption name in the titlebar, but the list produces the .exe name. The EnumProcesses does produce an array or process Id`s. Its probably better killing them by that. I`ll have a look for you(or does Madshi already know?)

As I've stated in my first comment, there are (at least) 3 ways of closing an application. When only having the processID of the to-be-stopped process you can without much problems use OpenProcess + TerminateProcess. Getting the main window of a processID (for the WM_CLOSE solution) is a bit more work, you need to call EnumWindows and then GetWindowThreadProcessID for each enumerated window. The biggest problem is the PostThreadMessage solution, since psApi.dll can't enumerate threads. But I suggest moving the closing question to Bloodline's new question, which is already online...

Madshi,
Thanks for the comments. I havent had time today to look at the closing of the apps. Its something worth playing with for Bloodline (and myself) cos in my eyes thats the only way to learn. I didnt know about Bloodlines other question. Again, Ive learned from you and Ive took your comments on board. thanks

Bloodline,
Many thanks for the points, Im not really in it for the points, I just come here to learn new things and help out, but its always nice to know when your help and time is appreciated. Good luck with your codeing.
Regards
Smurff

Looking into this further Ive also found this. I dont know where it came from, it was just in my "Delphi Crap to sort" directory :) It might help you learn more about the whole "process" thing. anyway thought it might help.
Regards
Smurff

Objective:
- This article will help user in how to convert their numeric value become words.
How to use
1. You can copy this code in your Unit as function
2. than you can perform your function by type this code
The Code
(CODE)
The Im…

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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg).
If you're looking for how to monitor bandwidth using netflow or packet s…

This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory.
NOTE: For Outlook 2016 and 2013 perform the exact same steps.
Open a new email: Click the New email button in Outlook.
Start typing the address: …