如何通过PID号来结束进程。(60分)

  • 主题发起人 主题发起人 Tanni
  • 开始时间 开始时间
T

Tanni

Unregistered / Unconfirmed
GUEST, unregistred user!
如何通过PID号来结束进程。[8D][8D]
 
来自:jsxjd, 时间:2002-11-22 12:19:00, ID:1450931<br>----------------------------------------------------------------<br><br>//获得进程列表,并终止 Excel 进程<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; FSnapshotHandle:THandle;<br>&nbsp; FProcessEntry32:TProcessEntry32;<br>&nbsp; Ret : BOOL;<br>&nbsp; ProcessID : integer;<br>&nbsp; s:string;<br>begin<br>&nbsp; FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br>&nbsp; Ret:=Process32First(FSnapshotHandle,FProcessEntry32);<br>&nbsp; Memo1.clear;<br>&nbsp; while Ret do<br>&nbsp; begin<br>&nbsp; &nbsp; Memo1.lines.add(FProcessEntry32.szExeFile);<br>&nbsp; &nbsp; s:=ExtractFileName(FProcessEntry32.szExeFile);<br>&nbsp; &nbsp; if s='EXCEL.EXE' then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ProcessID:=FProcessEntry32.th32ProcessID;<br>&nbsp; &nbsp; &nbsp; TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,ProcessID),1);<br>&nbsp; &nbsp; &nbsp; s:='';<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Ret:=Process32Next(FSnapshotHandle,FProcessEntry32);<br>&nbsp; end;<br>end;<br>
 
我想KILL的是DLLHOST产生的进程,PID号我是已经有了的,以上这种方法我已用过,不过<br>经常KILL不了。
 
后退
顶部