• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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!
0
AngeloX
Asked:
AngeloX
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now