procedure TerminateApplication(AppName: String);
const
PROCESS_TERMINATE = $0001;
var
b1, b2: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
FModuleHandle: THandle;
FModuleEntry32: TModuleEntry32;
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
b1:=Process32First(FSnapshotHandle, FProcessEntry32);
while b1do
begin
FModuleHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPMODULE,FProcessEntry32.th32ProcessID);
FModuleEntry32.dwSize:=SizeOf(TModuleEntry32);
b2:=Module32First(FModuleHandle,FModuleEntry32);
while b2do
begin
if SameText(FModuleEntry32.szExePath,AppName) then
TerminateProcess(OpenProcess(PROCESS_TERMINATE,False,
FProcessEntry32.th32ProcessID),0);
b2:=Module32Next(FModuleHandle,FModuleEntry32);
end;
CloseHandle(FModuleHandle);
b1:=Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;