杀死进程函数为何一直占用内存?附源码~! ( 积分: 100 )

  • 主题发起人 主题发起人 剑魂
  • 开始时间 开始时间

剑魂

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses TlHelp32,IniFiles,HideProcess;
{$R *.dfm}

function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result:= 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))
=UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile)
=UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;

function split(s,s1:string):TStringList;
begin
Result:=TStringList.Create;
while Pos(s1,s)>0 do
begin
Result.Add(Copy(s,1,Pos(s1,s)-1));
Delete(s,1,Pos(s1,s));
end;
Result.Add(s);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
CurrentWindow:Thandle;
rzreg:TIniFile;
s,v:TStringList;
sztext: array[0..254] of char;
I,Q:integer;
begin
// MyHideProcess;
Form1.Hide;
rzreg:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'killini.ini');
s:=split(RzReg.ReadString('程序配置','禁止标题',''),',');
for I:=0 to s.Count-1 do
begin
CurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while CurrentWindow <> 0 do
begin
GetWindowText(CurrentWindow, @sztext, 255);
if pos(s,sztext)<>0 then
begin
postmessage(currentwindow,wm_close,0,0);//关闭该页面
end;
CurrentWindow := GetWindow(CurrentWindow, GW_HWNDNEXT);
end;
end;

KillTask('cdd.exe');
end;
v.Free;
s.Free;
rzreg.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
Form1.Top:=10000;
end;

end.
 
内存一点一点加,一直加到1G多,郁闷~~~~
 
自己搞定了:)
有个句柄忘记关闭了~~~
 
太深了,没看出来
 
一堆代码看了头大
 

Similar threads

I
回复
0
查看
597
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
600
import
I
后退
顶部