下面的这段代码就可以完全实现你的要求
俺现在太穷啦,快点给分吧
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, ExtCtrls, StdCtrls, ScktComp;
type
TProcessInfo=Record //取得系统运行的进程列表
ExeFile:String;
ProcessId
WORD;
end;
ProcessInfo=^TProcessInfo;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcessListHandle:THandle;
h:THandle;
a
WORD;
p
RocessInfo;
ok:Bool;
ProcessStruct:TProcessEntry32;
Begin
ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
ProcessStruct.dwSize:=Sizeof(ProcessStruct);
ok:=Process32First(ProcessListHandle,ProcessStruct);
while Integer(ok)<>0 do Begin
new(p);
p.ExeFile:=ProcessStruct.szExeFile; //Process Name
p.ProcessID:=ProcessStruct.th32ProcessID; //Process ID
// listbox1.Items.Add(p.exefile); //add Process Name to Listbox1
ok:=Process32Next(ProcessListHandle,ProcessStruct);
if p.ExeFile='word.exe' then begin //if Process='word.exe' then TerminateProcess
h:=openProcess(Process_All_Access,true,p.ProcessId);
GetExitCodeProcess(h,a);
if Integer(TerminateProcess(h,a))<>0 then
try terminateprocess(h,a); except end;
end;
end;
end;