?? tkillprocess.pas
字號:
unit Tkillprocess;
interface
uses
SysUtils,
windows,
Classes,
Messages,
TLHelp32;
type
Killprocess = class(TObject)
process:Tstrings;
processID:Tstrings;
processThreads:Tstrings;
procedure clear;
procedure killID(pid:Thandle);
procedure getprocess;
function killprocess(Parastr:string):BOOL;
function killform(prc:string):BOOL;
function ProcessExist(Parastr:string):BOOL;
constructor create;
destructor Destroy;override;
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
constructor killprocess.create;
begin
inherited Create;
self.process:=Tstringlist.Create;
self.processID:=Tstringlist.Create;
self.processThreads:=Tstringlist.Create;
end;
destructor killprocess.Destroy;
begin
inherited destroy;
self.process.Destroy;
self.processID.Destroy;
self.processThreads.Destroy;
end;
procedure killprocess.clear;
begin
self.process.Clear;
self.processID.Clear;
self.processThreads.Clear;
end;
procedure killprocess.getprocess;
var
snapHandle:Thandle;
procMap:TprocessEntry32;
continue:Bool;
begin
snapHandle:=createtoolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
procMap.dwSize:=Sizeof(procMap);
continue:=process32First(snapHandle,procMap);
while integer(continue)<>0 do
begin
self.process.Add(extractfileName(procMap.szexefile));
self.processID.Add(inttostr(procMap.th32ProcessID));
self.processThreads.Add(inttostr(procmap.cntThreads));
continue:=Process32Next(snapHandle,procMap);
end;
CloseHandle(snapHandle);
end;
function killprocess.killform(prc:string):BOOL;
var
hWndClose: HWnd;
BO:BOOL;
begin
BO:=false;
hWndClose := FindWindow(nil, pchar(prc));
while(hWndClose <> 0) do
begin
SendMessage(hWndClose,WM_CLOSE,0,0);
BO:=true;
hWndClose := FindWindow(nil, pchar(prc));
end;
CloseHandle(hWndClose);
Result:=BO;
end;
function killprocess.ProcessExist(Parastr:string):BOOL;
var
p:integer;
have:BOOL;
begin
p:=0;
self.getprocess;
have:=false;
while p<self.process.Count do
begin
if lowercase(self.process.Strings[p])=Parastr then
begin
have:=true;
break;
end;
inc(p);
end;
self.clear;
Result:=have;
end;
procedure killprocess.killID(pid:Thandle);
var
Handle: THandle;
begin
Handle:=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
TerminateProcess( Handle, 0 );
WaitForSingleObject(Handle, INFINITE);
closeHandle(handle);
end;
function killprocess.killprocess(Parastr:string):BOOL;
var
p:integer;
have:BOOL;
begin
p:=0;
self.clear;
getprocess;
have:=false;
while p<self.process.Count do
begin
if lowercase(self.process.Strings[p])=Parastr then
begin
killID(strtoint(self.processID.Strings[p]));
have:=true;
//break;
end;
inc(p);
end;
self.clear;
Result:=have;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -