W
walala
Unregistered / Unconfirmed
GUEST, unregistred user!
下面这段程序证实了我的适想:
win95里有当前程序的列表。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
tlhelp32, StdCtrls;
type TProcessInfo = record
ExeFile: string;
ProcessIDWORD;
end;
ProcessInfo = ^TProcessInfo;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure ProcessList(var Plist:Tlist);
public
{ Public declarations }
Current:Tlist;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Tform1.ProcessList(var Plist:Tlist);
var
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 okdo
begin
new(p);
p.ExeFile:=ProcessStruct.szExeFile;
p.ProcessID:=ProcessStruct.th32ProcessId;
Plist.Add(p);
ok:=Process32next(ProcesslistHandle,ProcessStruct);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
processInfo;
begin
current:=Tlist.Create;
current.Clear;
listbox1.Clear;
ProcessList(current);
for i:=0 to current.Count-1do
begin
new(p);
p:=current.Items;
listbox1.Items.Add(p.exefile);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h:Thandle;
aWORD;
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
listbox1.Clear;
formcreate(self);
end;
end;
end;
end.
tlhelp32,TProcessEntry32 请大家介绍一下,懒得查资料。
win95里有当前程序的列表。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
tlhelp32, StdCtrls;
type TProcessInfo = record
ExeFile: string;
ProcessIDWORD;
end;
ProcessInfo = ^TProcessInfo;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure ProcessList(var Plist:Tlist);
public
{ Public declarations }
Current:Tlist;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Tform1.ProcessList(var Plist:Tlist);
var
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 okdo
begin
new(p);
p.ExeFile:=ProcessStruct.szExeFile;
p.ProcessID:=ProcessStruct.th32ProcessId;
Plist.Add(p);
ok:=Process32next(ProcesslistHandle,ProcessStruct);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
processInfo;
begin
current:=Tlist.Create;
current.Clear;
listbox1.Clear;
ProcessList(current);
for i:=0 to current.Count-1do
begin
new(p);
p:=current.Items;
listbox1.Items.Add(p.exefile);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h:Thandle;
aWORD;
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
listbox1.Clear;
formcreate(self);
end;
end;
end;
end.
tlhelp32,TProcessEntry32 请大家介绍一下,懒得查资料。