为什么我删除不了进程呢?看看下面的代码(100分)

J

jadesun

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics,
TLHelp32,Controls, Forms, Dialogs, StdCtrls, XPMenu, ComCtrls;

type
TProcessInfo = Record
ExeFile : String;
ProcessID : DWORD;
end;
pProcessInfo = ^TProcessInfo;

type
TForm1 = class(TForm)
XPMenu1: TXPMenu;
Button1: TButton;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var lppe: TProcessEntry32;
found : boolean;
Hand : THandle;
begin
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
found := Process32First(Hand,lppe);
while found do
begin
listbox1.Items.Add(StrPas(lppe.szExeFile));
found := Process32Next(Hand,lppe);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Exehandle: THandle;
s : String;
i:integer;
begin
i:=listbox1.ItemIndex ;
s := listbox1.Items;
ExeHandle:=Findwindow(nil,pchar(s));
if ExeHandle<>0 then
PostMessage(ExeHandle,WM_CLOSE,0,0);
end;

end.
 
Button1Click 是删除进程事件
 
进程.ExeFile<>进程.主窗口.Caption
 
能告诉我应该怎么做吗?
 
拿着这个: TProcessEntry32.th32ProcessID (进程ID)
调用这个: ProcessHandle:=OpenProcess(nil,false,aProcessID); (取得进程句柄)
然后这个: TerminateProcess(ProcessHandle,123); (关闭进程)
 
谢谢你,能写得详细一些吗?
 
谢谢,问题解决了
 
谢谢两位
 
多人接受答案了。
 
顶部