Entwickler-Ecke

Windows API - How do I kill a aplication?


Stianbl - So 11.07.04 17:18
Titel: How do I kill a aplication?
Hi again!
Ok, I don`t know where to post this, curse the forum is in german.. :roll:

I hav an irritating program that starts several times on my computer, and I want to make a program in delphi 6 that "kill`s" the program!
You know: End the prosess...
I will not delete the program, I have to stop the prosess... Like when you push ctrl+alt+del in windows and "kill" it.
I need my delphi program to search for programs running every 5th minute, and then close the prosess I set it to...

Thanks in advance! 8)


Moderiert von user profile iconPeter Lustig: Moved from Dateizugriff on So 11.07.2004 at 17:30


raziel - So 11.07.04 17:47

Hi,

Try to find the program via FindWindow and kill it by either using TerminateProcess or sending a WM_CLOSE Message to the program.
To find a Window using FindWindow you need the ClassName and the WindowName. Both can be retrieved with a tool called Suche in: Delphi-Forum, Delphi-Library X-SPY.

raziel


Stianbl - So 11.07.04 19:25

Thanks m8! :D
But could you make a simple example code for me?
Lets say that the program`s name is: "test123"

If you could do this, I would be very happy! :wink:

Thanks in advance! 8)


Alexander F - So 11.07.04 21:10

Try this:

Delphi-Quelltext
1:
]  SendMessage(FindWindow('notepad'nil), WM_CLOSE, 00);                    

I haven't checked it, but I hope it will work.... 8)


Delete - So 11.07.04 21:42

If you have only the name of the executable, try this: http://www.luckie-online.de/Ablage/Delphi-Quellcodes/CreateToolHelp32Snapshot.html


Stianbl - So 11.07.04 23:03

Thanks for all the help! :D
This is a really great forum! :wink:

<edit:>
but if I would like it to close the game Warcraft III, that uses the file war3.exe, shouldn`t the code be like this then? SendMessage(FindWindow('war3.exe', nil), WM_CLOSE, 0, 0); ???
Course thisone doesn`t work!
Whan I write notepad instead of war3.exe, it works! :?
</edit:>

<edit2:>
I read that link you gave me, but I don`t know a word in dutch!!! :lol:
Witch one do I have to use?
</edit2:>

Sorry for all my questions... 8)


Delete - So 11.07.04 23:13

Notepad is the name of the window class, too. And so it works. If you want to kill an executable with or by its name, you should use Luckie's unit. Make a peep, if you have problems with his German commentaries. ;)


Stianbl - So 11.07.04 23:23

I see it now! :wink: hehe...
But could you copy out the lines I need to use form that page Luckie sendt, course I don`t know a single word in german, dutch or what ever it is! :P lol!

And thanks!


Delete - Mo 12.07.04 00:02

It's German, I guess. (@Luckie: :mrgreen:) Seriously --

Start a new project and put a listbox and two buttons onto your form. Then copy everything what you see in Luckie's sample code -- excluding the two button click procedures at the bottom.

So, now double-click the first button and fill it with the two lines, you see in the "Button1Click" procedure. Then double-click the second button and fill it with the line, you see in "Button2Click".

Now compile and try it:
Using the first button will fill your listbox with all running processes.
Select one and click the second button to kill the selected process.

That's all.
Try to analyze the code and (especially) its steps and you understand what happens.



To all the Germans here: Am I so bad? Altavista's translation:
Zitat:
It's Deutscher, schätze ich. (@Luckie: :mrgreen:) Ernsthaft -- Beginnen Sie ein neues Projekt und setzen Sie ein listbox und zwei Tasten auf Ihre Form. Kopieren Sie dann alles, was Sie in Luckie's Beispielcode -- [ b]excluding[/b ] die zwei Taste Klickenverfahren an der Unterseite sehen. So jetzt füllt Doppeltklicken die erste Taste und sie mit den zwei Linien, Sie sieht in das "Button1Click" Verfahren. Dann füllt Doppeltklicken die zweite Taste und sie mit der Linie, Sie sieht in "Button2Click". Jetzt kompilieren Sie und versuchen Sie es: Das Verwenden der ersten Taste füllt Ihr listbox mit allen laufenden Prozessen. Wählen Sie ein vor und klicken Sie die zweite Taste an, um den vorgewählten Prozeß zu töten. That's alle. Versuchen Sie, den Code zu analysieren und (besonders) verstehen seine Schritte und Sie, was geschieht.

:cry:


Delete - Mo 12.07.04 00:45

Stianbl hat folgendes geschrieben:
I see it now! :wink: hehe...
But could you copy out the lines I need to use form that page Luckie sendt, course I don`t know a single word in german, dutch or what ever it is! :P lol!

And thanks!

Well, I thought, if you post in a German Delphi Board, your German is good enough to understand my code. Besides the important procedure names are in english. Guess what KillProcess does ;)


Stianbl - Mo 12.07.04 01:10

Yeah! :wink:
Ok.. Thanks for all the help!
I`ll try it all...