function KillProcess(ProcsName:String;CaseFlag:Boolean=false):Boolean;
var
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
ProcessID: Integer;
ProcessHndle: THandle;
ContinueLoop: BOOL;
ItemName, ItemFile: String;
Condition : boolean;
begin
result:= false;
try
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop)<>0 do begin
ItemFile := ExtractFileName(FProcessEntry32.szExeFile);
ProcessID := FProcessEntry32.th32ProcessID;
ItemName := FProcessEntry32.szExeFile;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
if CaseFlag then
Condition := (UpperCase(ItemFile) = uppercase(ProcsName)) or (UpperCase(ItemName) = uppercase(ProcsName))
else
Condition := (ItemFile = uppercase(ProcsName)) or (ItemName = uppercase(ProcsName)) ;
if Condition then begin
ProcessHndle := OpenProcess(PROCESS_TERMINATE, BOOL(0), ProcessID);
Result:= TerminateProcess(ProcessHndle, 0) ;
end;
end;
except
exit;
end;
end;
//CaseFlag 是决定打小敏感的开关.ProcsName是你的进程名.
你用KillProcess('WINWORD');试试.