procedure Tsyste.procedu(var str:string); //得到当前的进程名和ID
var FSnap:Thandle;
PE:TprocessEntry32;
PPE:PProcessEntry32;
str:string;
begin
if FSnap>0 then closeHandle(FSnap);
FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if FSnap=-1 then
raise Exception.create('Windows发生致命错误即将关闭!');
PE.dwsize:=sizeof(PE);
if Process32first(FSnap,PE) then
repeat
New(PPE);
PPE^:=PE;
str:=PPE.Th32processID
until Not Process32next(FSnap,PE);
end;
后面的自己加到程序里
var id:int64;
h,a:thandle;
Id:=strtoint64(str);//杀进程
h:=openprocess(PROCESS_ALL_ACCESS,True,Id);
getExitCodeProcess(h,a);
var FSnap:Thandle;
PE:TprocessEntry32;
PPE:PProcessEntry32;
str:string;
begin
if FSnap>0 then closeHandle(FSnap);
FSnap:=createtoolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if FSnap=-1 then
raise Exception.create('Windows发生致命错误即将关闭!');
PE.dwsize:=sizeof(PE);
if Process32first(FSnap,PE) then
repeat
New(PPE);
PPE^:=PE;
str:=PPE.Th32processID
until Not Process32next(FSnap,PE);
end;
后面的自己加到程序里
var id:int64;
h,a:thandle;
Id:=strtoint64(str);//杀进程
h:=openprocess(PROCESS_ALL_ACCESS,True,Id);
getExitCodeProcess(h,a);
解决方案 »
- Java调用Delphi的DLL问题
- 如何获取窗口Form1调整后的窗口width和heigth?
- 国际象棋组件
- 一个简单问题,TLabel显示的东西如何换行显示啊?
- 编写三层分布世数据库程序用什么开发工具能够具有较好的安全性?
- 在delphi中使用Tregistry读取注册表信息,该如何读取二进制数值转换成字符串型并且只显示想要得数据位?
- 怎样通过netbios获得远程主机机器名和以及工作组名称,以及操作系统等情况!
- 又是一个菜鸟问题,知道一个进程的HANDLE,怎样得到它的ProcessId?
- 什么是控件?
- 哪里可以下载的好的组件?
- Active Movie 控件 导致 Form无法保存,为什么?
- 我是新手,刚开始用EDITPLUS,出了点小问题,请帮忙!!!
代码如下: (纯 win32 API)
program window;uses
windows, Messages, sysutils,TLhelp32;
const
appname = 'Porter';
App1 = 'notepad.exe';
App2 = 'notepad.exe';
TimeLen = 10000;var
Ok : Bool;
ProcessListHandle : hwnd;
ProcessStruct : TProcessEntry32;
amessage : tmsg;
hwindow : hwnd;
H : hwnd;
A : DWORD;function RegisterServiceProcess(dwProcessID, dwType: Integer): Integer;
stdcall; external 'KERNEL32.DLL';function windowproc(window : hwnd; amessage,wparam,lparam : longint) : longint;stdcall;export;
begin
windowproc := 0; case amessage of
wm_destroy :
begin
killtimer(window,1);
postquitmessage(0);
exit;
end;
wm_create :
begin
SetWindowLong(window,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
RegisterServiceProcess(GetCurrentProcessID, 1);
settimer(window,1,TimeLen,nil);
end;
wm_timer :
begin
ProcessListHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);
ProcessStruct.dwsize := SizeOf(ProcessStruct);
Ok := Process32First(ProcessListHandle,ProcessStruct); while integer(Ok) <> 0 do
begin
if (lowercase(extractfilename(ProcessStruct.szExeFile)))= App1 or
(lowercase(extractfilename(ProcessStruct.szExeFile)))= App2
then
begin
H := OpenProcess(PROCESS_ALL_ACCESS,True,ProcessStruct.th32ProcessID);
GetExitCodeProcess(H,A);
if integer(TerminateProcess(H,A)) <> 0 then
begin
end;
end;
Ok := Process32Next(ProcessListHandle,ProcessStruct);
end;
end;
end; windowproc := defwindowproc(window,amessage,wparam,lparam);
end;function winregister : boolean;
var
windowclass : twndclass;
begin
//windowclass.style := cs_redraw or cs_vrdraw;
windowclass.lpfnwndproc := @windowproc;
windowclass.cbclsextra := 0;
windowclass.cbwndextra := 0;
// windowclass.histance := hinstance;
windowclass.hicon := loadicon(0,idi_application);
windowclass.hcursor := loadcursor(0,idc_arrow);
windowclass.hbrbackground := hbrush(color_window);
windowclass.lpszmenuname := nil;
windowclass.lpszclassname := appname; result := registerclass(windowclass) <>0;
end;function wincreate : hwnd;
var
hwindow : hwnd;
begin
hwindow := createwindow(appname,'Porter',ws_overlappedwindow,cw_usedefault,cw_usedefault,
cw_usedefault,cw_usedefault,0,0,hinstance,nil);
result := hwindow;
end;//main
begin
if not winregister then exit; hwindow := wincreate; if hwindow = 0 then exit; while getmessage(amessage,0,0,0) do
begin
translatemessage(amessage);
dispatchmessage(amessage);
end; halt(amessage.wparam);
end.
var
DLLinst:THandle;
ok:boolean;
LPPROCESSENTRY32:TPROCESSENTRY32;
i:integer;
begin
ListBox1.Clear;
DLLinst:=LoadLibrary('KERNEL32.DLL');
if Dllinst>0 then
begin
GetProcAddress(DLLinst,'CreateToolhelp32Snapshot');
ProcessListHandle:=CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
LPPROCESSENTRY32.dwSize:=Sizeof(LPPROCESSENTRY32);
ok:=Process32First(ProcessListHandle,LPPROCESSENTRY32);
end;
i:=0;
while ok do
begin
ListBox1.Items.Add(Lpprocessentry32.szExeFile);
ok:=Process32Next(ProcesslistHandle,LPPROCESSENTRY32);
Process[i]:=OpenProcess(PROCESS_TERMINATE,True,LPPROCESSENTRY32.th32ProcessID);
i:=i+1;
end;
CloseHandle(ProcesslistHandle);
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
now:integer;
exitcode:DWord;
begin
if Listbox1.ItemIndex<0 then
ShowMessage('嘿嘿...这也太欺负我们小猪了,总得先选个目标吧!')
else
begin
now:=Listbox1.ItemIndex-1;
GetExitCodeProcess(Process[now],exitcode);
if TerminateProcess(Process[now],exitcode) then
Listbox1.Clear
else if PostMessage(Process[now],WM_QUIT,0,0) then
ListBox1.Clear
else ShowMessage('呜呜... 俺小猪无能为力了!'); end;end;
楼上的几位对不对呀????如果对了就赶快加分吧.