S
startzero
Unregistered / Unconfirmed
GUEST, unregistred user!
//====================检索遍历进程找出要挂接的explorer.exe进程ID===============
function FindProcessName(proname:string):THandle;
var
lppe: tprocessentry32;
sshandle: thandle;
found: boolean;
begin
result:=0;
sshandle := createtoolhelp32snapshot(TH32CS_SNAPALL, 0);
found := process32first(sshandle, lppe);
while found do
begin
if ansiCompareText(ExtractFileName(lppe.szExefile),proname) = 0 then
begin
result:=lppe.th32ProcessID;
break;
end;
found := process32next(sshandle, lppe); {检索下一个进程}
end;
CloseHandle(sshandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h,hprocess:hwnd;
begin
h:=FindProcessName('elementclient.exe');
hProcess:=openprocess(PROCESS_TERMINATE,FALSE,h);
edit1.Text:=inttostr(hprocess);
//注意就这里了,没有这句,程序不执行。无法结束进程。
//一句无关紧要的东西,也能引响到代码,天啊,是不是我的D7要重装了,是不是坏了。
if TerminateProcess(hprocess,3838) then
showmessage('成功');
end;
function FindProcessName(proname:string):THandle;
var
lppe: tprocessentry32;
sshandle: thandle;
found: boolean;
begin
result:=0;
sshandle := createtoolhelp32snapshot(TH32CS_SNAPALL, 0);
found := process32first(sshandle, lppe);
while found do
begin
if ansiCompareText(ExtractFileName(lppe.szExefile),proname) = 0 then
begin
result:=lppe.th32ProcessID;
break;
end;
found := process32next(sshandle, lppe); {检索下一个进程}
end;
CloseHandle(sshandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
h,hprocess:hwnd;
begin
h:=FindProcessName('elementclient.exe');
hProcess:=openprocess(PROCESS_TERMINATE,FALSE,h);
edit1.Text:=inttostr(hprocess);
//注意就这里了,没有这句,程序不执行。无法结束进程。
//一句无关紧要的东西,也能引响到代码,天啊,是不是我的D7要重装了,是不是坏了。
if TerminateProcess(hprocess,3838) then
showmessage('成功');
end;