unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Buttons,TlHelp32;<br><br>type<br> ///////////////////////////////<br> TProcessInfo=Record<br> ExeFile:string;<br> ProcessID
word;<br> end;<br> ProcessInfo=^TProcessInfo;//////////<br> TForm1 = class(TForm)<br> BitBtn1: TBitBtn;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br>//////////////////////////////////////////////////////////////////////////////<br>//11.取得当前进程列表<br>//////////////////////////////////////////////////////////////////////////////<br>procedure ProcessList(Var pList:TList);<br>var p
rocessInfo;<br> ok:Bool;<br> ProcessListHandle:THandle;<br> ProcessStruct:TProcessEntry32;<br>begin<br> pList:=TList.Create;<br> pList.Clear;<br> ProcessListHandle:=CreateToolHelp32SnapShot(TH32cs_SnapProcess,0);<br> ProcessStruct.dwSize:=SizeOf(ProcessStruct);<br> ok:=Process32First(ProcessListHandle,ProcessStruct);<br> while integer(ok)<>0 do<br> begin<br> New(p);<br> p.ExeFile:=ProcessStruct.szExeFile;<br> p.ProcessID:=ProcessStruct.th32ProcessID;<br> pList.Add(p);<br> ok:=Process32Next(ProcessListHandle,ProcessStruct);<br> end;<br> // dispose(p); //释放内存<br>end;<br>//////////////////////////////////////////////////////////////////////////////<br>//12.终止某一正在运行的进程<br>//////////////////////////////////////////////////////////////////////////////<br>procedure HideProcess(ProcessName:string);<br>var h:Thandle;<br> a
word;<br> p
rocessInfo;<br> i:integer;<br> Current:TList;<br>begin<br> ProcessList(current);<br> for i:=0 to current.Count-1 do<br> begin<br> p:=Current.Items
;<br> if ansiuppercase(p.ExeFile)=ansiuppercase(ProcessName) then<br> begin<br> h:=OpenProcess(Process_All_Access,true,p.ProcessID);<br> GetExitCodeProcess(h,a);<br> TerminateProcess(h,a);<br> end;<br> end;<br>end;<br>////////////////////////////////////////////////////////////////////////////////<br>//13.查找进程<br>////////////////////////////////////////////////////////////////////////////////<br>function FindProcess(ProcessName:string):Bool;<br>var<br> processInfo;<br> i:integer;<br> Current:TList;<br>begin<br> result:=false;<br> ProcessList(current);<br> for i:=0 to current.Count-1 do<br> begin<br> p:=Current.Items;<br> if ansiuppercase(p.ExeFile)=ansiuppercase(ProcessName) then<br> begin<br> result:=true;<br> break;<br> end;<br> end;<br> Current.Free;<br> dispose(p); //释放内存<br>end;<br>end.