var wnd:HWND; begin wnd:=Findwindow('p1.exe',nil); if wnd>0 then sendMessage(wnd,WM_CLOSE,0,0);//发送关闭消息
sendMessage(wnd,WM_CLOSE,0,0);//发送关闭消息 不能关闭该程序吗?
有些程序的close???事件中的canclose是为False的。这样可以关闭吗?
给wwwwwa 刚测试了一下 ,不能关闭。
Wnd的返回值总是0,但是程序确实在运行
uses tlhelp32; 假设要终止的程序的文件名为:p1.exe,那么例程如下: var lppe:tprocessentry32; sshandle:thandle; hh:hwnd; found:boolean; begin sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0); found:=process32first(sshandle,lppe); while found do begin //进行处理,其中lppe.szExefile就是程序名。 if uppercase(extractfilename(lppe.szExeFile))='P1.EXE' then begin hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID); TerminateProcess(hh,0); end; found:=process32next(sshandle,lppe); end; end;
wnd:HWND;
begin
wnd:=Findwindow('p1.exe',nil);
if wnd>0 then
sendMessage(wnd,WM_CLOSE,0,0);//发送关闭消息
不能关闭该程序吗?
刚测试了一下 ,不能关闭。
假设要终止的程序的文件名为:p1.exe,那么例程如下:
var
lppe:tprocessentry32;
sshandle:thandle;
hh:hwnd;
found:boolean;
begin
sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);
found:=process32first(sshandle,lppe);
while found do
begin
//进行处理,其中lppe.szExefile就是程序名。
if uppercase(extractfilename(lppe.szExeFile))='P1.EXE' then
begin
hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);
TerminateProcess(hh,0);
end;
found:=process32next(sshandle,lppe);
end;
end;
尽快结贴吧。