如何获得当前运行的所有进程,并且如何关闭???

alwssoan 2001-07-08 06:03:17
如果获得当前系统中运行的所有的进程名,并且如果关闭其中的一个进程?
不要发表太短的议论,请给出具体代码或是片段,否则不给分
...全文
244 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
LittleStar 2001-07-10
  • 打赏
  • 举报
回复
MFC代码可以吗?
alwssoan 2001-07-09
  • 打赏
  • 举报
回复
up
alwssoan 2001-07-09
  • 打赏
  • 举报
回复
up
alwssoan 2001-07-09
  • 打赏
  • 举报
回复
up
BlueTrees 2001-07-09
  • 打赏
  • 举报
回复
如何Kill所有的进程,Windows没有提供标准的方法!有后门。
BlueTrees 2001-07-09
  • 打赏
  • 举报
回复
我说了吧:
标准的Kill进程方法,不是可以杀任何进程!
与我上面的例子配合使用,修改上面的例子:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tlhelp32, StdCtrls, Buttons, CheckLst;

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

var
Form1: TForm1;

procedure Search(Strings:TStrings);
implementation

{$R *.dfm}
procedure Search(Strings:TStrings);
var
Snap:THandle;
RB:Boolean;
PE:TProcessEntry32;
begin
if Strings=nil then
Exit;
snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if snap = -1 then Exit;
try
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32First(snap,PE);
while RB do
begin
Strings.AddObject(PE.szExeFile,Pointer(PE.th32ProcessID));
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32Next(snap,PE);
end;
finally
CloseHandle(snap);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
ListBox1.Items.Clear;
Search(ListBox1.Items);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
H:THandle;
R:Cardinal;
begin
H:=OpenProcess(PROCESS_TERMINATE,True,LongInt(ListBox1.Items.Objects[ListBox1.ItemIndex]));
R:=0;
TerminateProcess(H,R);
CloseHandle(H);
end;

end.
关键的:
procedure TForm1.Button1Click(Sender: TObject);
var
H:THandle;
R:Cardinal;
begin
H:=OpenProcess(PROCESS_TERMINATE,True,LongInt(ListBox1.Items.Objects[ListBox1.ItemIndex]));
R:=0;
TerminateProcess(H,R);
CloseHandle(H);
end;
其中ListBox1.Items.Objects[ListBox1.ItemIndex]是在遍历进程时存放的ProcessID
Jera 2001-07-09
  • 打赏
  • 举报
回复
杀进程:
procedure KilAPP(AHandle:Longint);
var
dwThreadId,dwProcessId:Dword;
hProcess:Thandle;
begin

dwThreadId := GetWindowThreadProcessId(AHandle,@dwProcessId);
hProcess:=OpenProcess(PROCESS_TERMINATE,FALSE,dwProcessId);
if hProcess<>NULL then
TerminateProcess(hProcess,0);

end;
Kingron 2001-07-09
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/154/154686.shtm
http://www.csdn.net/expert/topic/127/127502.shtm
BlueTrees 2001-07-08
  • 打赏
  • 举报
回复
再加分至少50,我再教你怎么Kill一个进程!!!!
BlueTrees 2001-07-08
  • 打赏
  • 举报
回复
最简单的一个例子:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Tlhelp32, StdCtrls, Buttons, CheckLst;

type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
ListBox1: TListBox;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

procedure Search(Strings:TStrings);
implementation

{$R *.dfm}
procedure Search(Strings:TStrings);
var
Snap:THandle;
RB:Boolean;
PE:TProcessEntry32;
begin
if Strings=nil then
Exit;
snap:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if snap = -1 then Exit;
try
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32First(snap,PE);
while RB do
begin
Strings.Add(PE.szExeFile);
PE.dwSize:=SizeOf(TProcessEntry32);
RB:=Process32Next(snap,PE);
end;
finally
CloseHandle(snap);
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Search(ListBox1.Items);
end;

end.
注意要在Uses中加入Tlhelp32单元
alwssoan 2001-07-08
  • 打赏
  • 举报
回复
up
alwssoan 2001-07-08
  • 打赏
  • 举报
回复
上面好像只是通过可执行文件来获得进程名,我是说要直接取得当前系统中运行的所有进程名,还有,最好是delphi的代码,谢谢了
luhongjun 2001-07-08
  • 打赏
  • 举报
回复
BCB的你可以改成DELPHI

获得当前激活的进程:
1:包含头文件tlhelp32.h
2:.cpp如下:

ListView2->Items->Clear();
TListItem *mItem;
AnsiString ExeFile;
Pointer pt,pt2;
unsigned int s;
DWORD size,size2;
HANDLE snapshot;
PROCESSENTRY32 processinfo;
processinfo.dwSize = sizeof(processinfo);
snapshot =
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (snapshot==NULL) return;
bool flag = Process32First (snapshot,&processinfo);
while (flag){

mItem=ListView2->Items->Add();
ExeFile=AnsiString(processinfo.szExeFile);
mItem->Caption=ExeFile;
mItem->SubItems->Add(
IntToStr(int(processinfo.th32ParentProcessID)));

mItem->SubItems->Add(
IntToHex(int(processinfo.th32ProcessID),8).UpperCase());
size=GetFileVersionInfoSize(ExeFile.c_str(),&size2);
pt=malloc(size);
GetFileVersionInfo(ExeFile.c_str(),NULL,size,pt);
if(VerQueryValue(pt,
"\\StringFileInfo\\040904E4\\FileVersion",
&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,
"\\StringFileInfo\\040904E4\\CompanyName",
&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
if(VerQueryValue(pt,
"\\StringFileInfo\\040904E4\\FileDescription",
&pt2,&s))
mItem->SubItems->Add(PChar(pt2));
free(pt);
flag = Process32Next(snapshot,&processinfo);
}

要杀除一个进程,必须获得该进程的父线成ID(避免仅仅杀除子进程)。

if (ListView2->SelCount==0){
MessageBox(Handle,"请首先选择一个进程!",
"中止进程",MB_OK¦MB_ICONWARNING);
return;
}
int pPid=StrToInt(ListView2->Selected->
SubItems->Strings[0]);
HANDLE ps = OpenProcess(1,false,pPid);
if(ps&&TerminateProcess(ps,-9)){
MessageBox(Handle,"成功中止进程!",
"中止进程",MB_OK¦MB_ICONINFORMATION);
}
else
MessageBox(Handle,"中止进程失败!",
"中止进程",MB_OK¦MB_ICONWARNING);


注:杀死进程2000下不能用

alwssoan 2001-07-08
  • 打赏
  • 举报
回复
up
alwssoan 2001-07-08
  • 打赏
  • 举报
回复
up
alwssoan 2001-07-08
  • 打赏
  • 举报
回复
up
manboo 2001-07-08
  • 打赏
  • 举报
回复
你可以去看看C++ Buider 5的例子在Examples里!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧