Shutting down another program.

Hey guys n gals,

Do you have the code to shut down another program with the PID of that program (you dont have to write how to get the PID, just how to shut down a program by using its PID).

If it's not possible to shut down a program by using its PID, then do you know how to get a windows handle of a PID to shut down a program by using its windows handle.

If it's not possible to get a window handle from a PID, then do you know how to find a Window Classname by Filename.

Thnx!
AngeloXAsked:
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.

din345Commented:
This will close an Internet Explorer window:

procedure TForm1.Button1Click(Sender: TObject);
const PROCESS_MURDER = $0001;
var pid: Cardinal;
    ProcessHandle: THandle;
begin
GetWindowThreadProcessId(FindWindow('IEFrame', nil),@pid);
ProcessHandle := OpenProcess(PROCESS_MURDER, FALSE, pid);
TerminateProcess(ProcessHandle,4);
end;
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
AngeloXAuthor Commented:
Hey, thnx for your reply but it's not really what I wanted.

If I had the WindowName I didnt have to post here, but I only have the PID and the FileName of the program. Any ideas?

Thnx!
0
din345Commented:
if you know the pid then use this code:
procedure TForm1.Button1Click(Sender: TObject);
const PROCESS_MURDER = $0001;
var pid: Cardinal;
    ProcessHandle: THandle;
begin
pid := $00000F5C; //process id here
ProcessHandle := OpenProcess(PROCESS_MURDER, FALSE, pid);
TerminateProcess(ProcessHandle,4);
end;
0
AngeloXAuthor Commented:
Yeah indeed. I replied too fast, was just about to post that hehe.

Thnx! Points given.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.