类型:转载 责任编辑:asp 日期:2007/03/01
如何在一个程序中结束另一个正在运行的程序。
推荐阅读
sendmessage(handle,wm_close)
大家用得最多的是发消息,即两个程序都定义同样值的消息。在这边程序发送这个消息给另外一个程序。当这个程序得到这个消息后就关闭自己。
uses tlhelp32;
假设要终止的程序的文件名为:project2.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))=project2.exe then
begin
hh:=openprocess(process_all_access,true,lppe.th32processid);
terminateprocess(hh,0);
end;
found:=process32next(sshandle,lppe);
end;
end;
********************
handle hprocess
windows nt/2000: the handle must have process_terminate access.
for more information, see process security and access rights.
所以要先使用
dword setsecurityinfo(
handle handle, // handle to object
se_object_type objecttype, // object type
security_information securityinfo, // buffer
psid psidowner, // new owner sid
psid psidgroup, // new primary group sid
pacl pdacl, // new dacl
pacl psacl // new sacl
);