Hola, yo he encontrado esto en trucomanía, a lo mejor te sirve:
1)_____________________________________
SABIENDO EL "TÍTULO"
enviandole un mensaje WM_CLOSE.
Por ejemplo, cerrar la calculadora de Windows:
procedure TForm1.Button1Click(Sender: TObject);
var
Mango:integer;
begin
Mango:=FindWindow(nil,'Calculadora');
if mango=0
then ShowMessage('No encuentro esa aplicacion')
else SendMessage(Mango,WM_CLOSE,0,0);
end;
2)_________________________________________
SABIENDO EL NOMBRE DEL EXE:
Añade TLHelp32 en el uses de tu form
procedure TForm1.Button2Click(Sender: TObject);
function CierraExe (FicheroExe:string):boolean;
function SacaExe(MangoW:HWND):string;
{Obtiene el EXE de una tarea}
{get EXE of a task}
var
Datos :TProcessEntry32;
hID

Word;
Snap : Integer;
begin
GetWindowThreadProcessId(MangoW,@hID);
Snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
try
Datos.dwSize:=SizeOf(Datos);
if(Process32First(Snap,Datos))then
begin
repeat
if Datos.th32ProcessID=hID then
begin
Result:=StrPas(Datos.szExeFile);
Break;
end;
until not(Process32Next(Snap,Datos));
end;
finally
Windows.CloseHandle(Snap);
end;
end;
function ObtieneVentanas(Mango: HWND;
ACerrar: Pointer): Boolean; stdcall;
begin
Result := True;
{Mango es el handle de la tarea encontrada}
{Si es el .EXE buscado, lo cierra}
if SacaExe(Mango)=UpperCase( String(ACerrar^) )then
begin
SendMessage(Mango,WM_Close,0,0);
String(Acerrar^):='CERRADO';
end;
end;
begin
EnumWindows( @ObtieneVentanas, Integer(@FicheroExe) );
Result:=(FicheroExe='CERRADO');
end;
begin
if CierraExe('C:\WINDOWS\NOTEPAD.EXE')
then ShowMessage ('Cerrado/Closed')
else ShowMessage ('No Encontrado/not Found');
end;
Otro método más sencillo:
procedure TForm1.Button1Click(Sender: TObject);
function KillTask(FileName:String):integer;
var
ContinueLoop:BOOL;
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
const
PROCESS_TERMINATE=$0001;
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop)<>0 do
begin
if
((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(FileName))
or (UpperCase(FProcessEntry32.szExeFile)=UpperCase(FileName)))
then
Result:=Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),
FProcessEntry32.th32ProcessID),0));
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
begin
KillTask('Notepad.exe');
end;
Espero que te ayude en algo
