Link to home
Start Free TrialLog in
Avatar of AngeloX
AngeloX

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of din345
din345

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AngeloX
AngeloX

ASKER

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!
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;
Avatar of AngeloX

ASKER

Yeah indeed. I replied too fast, was just about to post that hehe.

Thnx! Points given.