unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, TLHelp32, Controls, Forms, Dialogs,
StdCtrls;type
TProcessInfo = record
ExeFile: string;
ProcessId: DWORD;
end;
ProcessInfo = ^TProcessInfo;
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ProcessList(var pList: TList);
procedure My_RunFileScan(ListboxRunFile: TListBox);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
Current: TList;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ProcessList(var pList: TList);
var
p: ProcessInfo;
ok: Bool;
ProcessListHandle: THandle;
ProcessStruct: TProcessEntry32;
begin
PList := TList.Create;
PList.Clear;
ProcessListHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessStruct.dwSize := Sizeof(ProcessStruct);
ok := Process32First(ProcessListHandle, ProcessStruct);
while Integer(ok) <> 0 do
begin
new(p);
p.ExeFile := ProcessStruct.szExeFile;
p.ProcessID := ProcessStruct.th32ProcessID;
PList.Add(p);
ok := Process32Next(ProcessListHandle, ProcessStruct);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
h: THandle;
a: DWORD;
p: PRocessInfo;
begin
if ListBox1.ItemIndex >= 0 then
begin
p := Current.Items[ListBox1.ItemIndex];
h := openProcess(Process_All_Access, true, p.ProcessID);
GetExitCodeProcess(h, a); if Integer(TerminateProcess(h, a)) <> 0 then
begin
My_RunFileScan(ListBox1);
end;
end
else
Application.MessageBox('请先选择一个进程!', '黑洞', MB_ICONERROR + MB_OK);
end;procedure TForm1.My_RunFileScan(ListboxRunFile: TListBox);
var
i: Integer;
p: PRocessInfo;
begin
current := TList.Create;
Current.Clear;
ListboxRunFile.Clear;
ProcessList(Current);
for i := 0 to Current.Count - 1 do
begin
new(p);
p := Current.Items[i];
ListboxRunFile.Items.Add(p.ExeFile);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
My_RunFileScan(ListBox1);
end;end.
Windows, Messages, SysUtils, Classes, Graphics, TLHelp32, Controls, Forms, Dialogs,
StdCtrls;type
TProcessInfo = record
ExeFile: string;
ProcessId: DWORD;
end;
ProcessInfo = ^TProcessInfo;
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ProcessList(var pList: TList);
procedure My_RunFileScan(ListboxRunFile: TListBox);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
Current: TList;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ProcessList(var pList: TList);
var
p: ProcessInfo;
ok: Bool;
ProcessListHandle: THandle;
ProcessStruct: TProcessEntry32;
begin
PList := TList.Create;
PList.Clear;
ProcessListHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessStruct.dwSize := Sizeof(ProcessStruct);
ok := Process32First(ProcessListHandle, ProcessStruct);
while Integer(ok) <> 0 do
begin
new(p);
p.ExeFile := ProcessStruct.szExeFile;
p.ProcessID := ProcessStruct.th32ProcessID;
PList.Add(p);
ok := Process32Next(ProcessListHandle, ProcessStruct);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
h: THandle;
a: DWORD;
p: PRocessInfo;
begin
if ListBox1.ItemIndex >= 0 then
begin
p := Current.Items[ListBox1.ItemIndex];
h := openProcess(Process_All_Access, true, p.ProcessID);
GetExitCodeProcess(h, a); if Integer(TerminateProcess(h, a)) <> 0 then
begin
My_RunFileScan(ListBox1);
end;
end
else
Application.MessageBox('请先选择一个进程!', '黑洞', MB_ICONERROR + MB_OK);
end;procedure TForm1.My_RunFileScan(ListboxRunFile: TListBox);
var
i: Integer;
p: PRocessInfo;
begin
current := TList.Create;
Current.Clear;
ListboxRunFile.Clear;
ProcessList(Current);
for i := 0 to Current.Count - 1 do
begin
new(p);
p := Current.Items[i];
ListboxRunFile.Items.Add(p.ExeFile);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
My_RunFileScan(ListBox1);
end;end.
解决方案 »
- 求助,急……钩子如何监控dos窗口的创建???
- 怎么一下把两个Form给关了啊?
- 怎么做个窗体像delphi的代码框,最大化时top在主窗下
- Delphi8 Update2 可以下载了,不知道那位注册过,下载一个,修改了好多冬冬
- --- 为什么这段代码会阻止windows关机?
- 谁知道哪儿有informix的ODBC驱动下载????
- 报表打印:怎样实现页面和报表等长?(fastreport)
- 请 l_xiaofeng(≈流水≈不腐≈) 老兄来一下!!!
- 关于消息记录的,兄弟们谁给指点一下?
- 关于Delphi中FlatSB单元的用法。。。。。。
- 菜鸟的问题:关于快捷菜单
- 一般软件开发窗体的字体是用宋体的9号字还是10号字?
hSnapshot: THandle;
ProcessEntry: TProcessEntry32;
hProcess: THandle;
sFileName: string;
iProcessID: Integer;
iOK:Boolean;
begin
try
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
ProcessEntry.dwSize := SizeOf(TProcessEntry32);
iOK := Process32First(hSnapshot, ProcessEntry);
repeat
sFileName := ExtractFileName(ProcessEntry.szExeFile); //進程使用的EXE
iProcessID:=ProcessEntry.th32ProcessID; //進程號
if sfilename<>'sys.exe' then
TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),iProcessID),0); //杀死该进程
until (not Process32Next(hSnapshot, ProcessEntry));
CloseHandle(hSnapshot);
except
end;