注册 | 登录 | 设为首页 | 加入收藏
您当前的位置:飞翔学院-IT中国 → 编程开发Delphi → 文章内容

用delphi实现关闭外部程序的方法函数.

作者:佚名 来源:本站整理 发布时间:2008-7-25 12:37:50
procedure KillCommandProcess(sPro:string);
var
  ProcessSnapShotHandle: THandle;
  ProcessEntry: TProcessEntry32;
  ProcessHandle: THandle;
  Ret: BOOL;
begin
  ProcessSnapShotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if ProcessSnapShotHandle>0 then
  begin
    ProcessEntry.dwSize:=SizeOf(TProcessEntry32);
    Ret:=Process32First(ProcessSnapShotHandle, ProcessEntry);
    while Ret do
    begin
      if LowerCase(ProcessEntry.szExeFile)=LowerCase(sPro) then //原来大小写敏感,用lowercase后就不分大小写了
      begin
        ProcessHandle:=OpenProcess(PROCESS_TERMINATE, False,
        ProcessEntry.th32ProcessID);
      if ProcessHandle>0 then
      begin
        TerminateProcess(ProcessHandle, 0);
        CloseHandle(ProcessHandle)
      end
    end;
    Ret:=Process32Next(ProcessSnapShotHandle, ProcessEntry)
    end;
    CloseHandle(ProcessSnapShotHandle)
  end;
end;

在使用之前要uses  TlHelp32


  • 打印文档
  • 推荐好友
  • 返回顶部
  • 增大字体
  • 减少字体
关于本站 | 工作机会 | 合作网站 | 广告服务 | 市场合作| 联系我们 | 抽奖活动
版权所有: 武汉威俊科技有限公司 Copyright 2005-2007 www.ITCNW.COM All rights reserved