Shut down another EXE

I need sample code to detact and shut down an EXE.
jlisloAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

craig_capelCommented:
you can get the programs thread and just kill it.... or a more politer way, ask the program to shutdown.... the later is easier but the thread way is a little harder but does not ask questions i have code for both but heres the first method, if it does the trick great....

procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
begin
h:=findwindow('scicalc',nil);
sendmessage(h,wm_close,0,0);
end;

copy this and put it into a button, run calculator c:\windows\calc.exe and then execute the code....

also you can find out if the calc is running by the return value of the window handle "h"....

Craig C.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MadshiCommented:
jlislo, what do you know about the exe you want to detect and shutdown? The main window caption or class? Or just the executable file?
In the latter case you can download the free unit "enumStuff.pas" from my homepage:

http://beam.to/madshi

With this unit you can enumerate all running processes (function GetProcessList). You can then look whether the exe is running and if it is you have the processID. Then call OpenProcess to get a process handle and TerminateProcess to terminate the process.

Regards, Madshi.
0
andrewsmithCommented:
h:=findwindow(nil,

{you could also type the windows text here if you did not know the class name}

);
0
jlisloAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.