精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● Delphi>>其他>>终止一个应用程序

主题:终止一个应用程序
发信人: kingron( )
整理人: teleme(2001-03-25 20:38:12), 站内信件
下面是我以前写的一个测试程序,幸亏还没有删除:
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
);


【 在 st.efan 的大作中提到:】
:上次金龙版主说:用OpenProcess() & TerminateProcess(),
:我看了好几天的帮助,并且揣摩了好几天,
:可还是用不好,
:那位高手赐教一下用法,最好有实例.
:Thank U!
:
:......
 


----
<img src="http://uh1.gz.163.com photo?name=kingron" border=0 alt="我是谁?">  

[关闭][返回]