首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么强制结束一个进程

2012-02-10 
如何强制结束一个进程?请问如何强制结束一个进程?进程名为“ght.exe”,是恶意软件,有许多个这样的进程,在不

如何强制结束一个进程?
请问如何强制结束一个进程?进程名为“ght.exe”,是恶意软件,有许多个这样的进程,在不更改文件属性、注册表、系统设置等情况下如何全部结束?(注:是强制结束)请在编程时不要添加控件,运行程序它会自己进行,不需要人工干预。


[解决办法]
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;

procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$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;

CloseHandle(FSnapshotHandle);
end;


procedure explorer;
begin
try
KillTask ( 'explorer.exe ');
except;
exit;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
explorer;
end;


end.

[解决办法]
楼上的方法就可以
用TerminateProcess关闭进程

热点排行