干掉进程(100分)

  • 主题发起人 主题发起人 messah
  • 开始时间 开始时间
M

messah

Unregistered / Unconfirmed
GUEST, unregistred user!
如何检索到运行中的进程,然后KILL掉? <br>例如,IE浏览器在进程冲的名字是IEXPLORE.EXE,而在任务列表中可能随着打开网页的名字的改变而改变。请问怎样能准确干掉运行了的IE。<br>最好有详细代码。谢谢大家。
 
转:LeeChange的答案,骗个分,呵呵<br>uses<br> &nbsp;TlHelp32; &nbsp;<br>procedure TMainForm.KillCommandProcess;<br>var<br> ProcessSnapShotHandle: THandle;<br> ProcessEntry: TProcessEntry32;<br> ProcessHandle: THandle;<br> Ret: BOOL;<br>begin<br> ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> if ProcessSnapShotHandle&gt;0 then<br> begin<br> &nbsp; ProcessEntry.dwSize:=SizeOf(TProcessEntry32);<br> &nbsp; Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);<br> &nbsp; while Ret do<br> &nbsp; begin<br> &nbsp; &nbsp; if ProcessEntry.szExeFile='project1.exe' then //大小写敏感<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; ProcessHandle:=OpenProcess(PROCESS_TERMINATE, False,<br> &nbsp; &nbsp; &nbsp; &nbsp; ProcessEntry.th32ProcessID);<br> &nbsp; &nbsp; &nbsp; if ProcessHandle&gt;0 then<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; TerminateProcess(ProcessHandle, 0);<br> &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(ProcessHandle)<br> &nbsp; &nbsp; &nbsp; end<br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp; Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)<br> &nbsp; end;<br> &nbsp; CloseHandle(ProcessSnapShotHandle)<br> end<br>end;
 
晚了~~~<br>Function KillProcess(ProexeName: String): Integer;<br>Var<br> &nbsp;ok: BOOL;<br> &nbsp;ProcessListHandle: THandle; //进程列表的句柄<br> &nbsp;processStruct: TProcessEntry32; //进程的结构,进程的信息都在这个结构里<br> &nbsp;h: Thandle;<br> &nbsp;a: DWORD;<br>Begin<br> &nbsp;result := 0;<br> &nbsp;processListHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> &nbsp;ProcessStruct.dwSize := Sizeof(ProcessStruct);<br> &nbsp;ok := Process32First(ProcessListHandle, ProcessStruct);<br> &nbsp;While integer(ok) &lt;&gt; 0 Do<br> &nbsp; &nbsp;Begin<br> &nbsp; &nbsp; &nbsp;If Uppercase(ProcessStruct.szExeFile) = Uppercase(ProexeName) Then<br> &nbsp; &nbsp; &nbsp; &nbsp;Begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;h := openprocess(PROCESS_ALL_ACCESS, TRUE, ProcessStruct.th32ProcessID);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetExitCodeProcess(h, a);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If Integer(TerminateProcess(h, a)) &lt;&gt; 0 Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := result + 1;<br> &nbsp; &nbsp; &nbsp; &nbsp;End;<br> &nbsp; &nbsp; &nbsp;ok := Process32Next(ProcessListHandle, ProcessStruct);<br> &nbsp; &nbsp;End;<br>End;
 
接受答案
 
后退
顶部