zoukankan      html  css  js  c++  java
  • delphi杀进程的两种方式

    第一种:比较简单,根据标题,找到窗口,再找到进程,杀死进程

    [delphi] view plain copy
     
    1. procedure KillProgram(WindowTitle : string);  
    2. const  
    3.   PROCESS_TERMINATE = $0001;  
    4. var  
    5.   ProcessHandle : THandle;  
    6.   ProcessID: Integer;  
    7.   TheWindow : HWND;  
    8. begin  
    9.   TheWindow := FindWindow(nil, PChar(WindowTitle));  
    10.   GetWindowThreadProcessID(TheWindow, @ProcessID);  
    11.   ProcessHandle := OpenProcess(PROCESS_TERMINATE, FALSE, ProcessId);  
    12.   TerminateProcess(ProcessHandle,4);  
    13. end;  


    第二种:复杂一点,不过可获取的信息更多,其他功能的时候可以参考一下

    [delphi] view plain copy
     
    1. function KillTask(ExeFileName: string): integer;  
    2. const  
    3.   PROCESS_TERMINATE=$0001;  
    4. var  
    5.   ContinueLoop: BOOL;  
    6.   FSnapshotHandle: THandle;  
    7.   FProcessEntry32: TProcessEntry32;  
    8. begin  
    9.   result := 0;  
    10.   
    11.   FSnapshotHandle := CreateToolhelp32Snapshot  
    12.                      (TH32CS_SNAPPROCESS, 0);  
    13.   FProcessEntry32.dwSize := Sizeof(FProcessEntry32);  
    14.   ContinueLoop := Process32First(FSnapshotHandle,  
    15.                                  FProcessEntry32);  
    16.   
    17.   while integer(ContinueLoop) <> do  
    18.   begin  
    19.     if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =  
    20.          UpperCase(ExeFileName))  
    21.      or (UpperCase(FProcessEntry32.szExeFile) =  
    22.          UpperCase(ExeFileName))) then  
    23.       Result := Integer(TerminateProcess(OpenProcess(  
    24.                         PROCESS_TERMINATE, BOOL(0),  
    25.                         FProcessEntry32.th32ProcessID), 0));    
    26.     ContinueLoop := Process32Next(FSnapshotHandle,  
    27.                                   FProcessEntry32);  
    28.   end;  
    29.   
    30.   CloseHandle(FSnapshotHandle);  
    31. end;   

    另,word也可以根据标题结束进程,word的标题的规则是application的title + "-" + window的title

    http://blog.csdn.net/youthon/article/details/7247874

  • 相关阅读:
    CSDN博客 专用备份工具
    discuz 7.0 uc 同步登录方法
    delphi 子窗体最大化
    OO系统分析员之路用例分析系列(8)如何编写一份完整的UML需求规格说明书[整理重发]
    delphi 抓取网页内容的程序
    delphi messagebox 使用技巧
    windows mobile下实现程序安装和卸载
    纯真IP库算法
    delphi idhttp 使用方法
    最近评论回复汇总
  • 原文地址:https://www.cnblogs.com/findumars/p/7230747.html
Copyright © 2011-2022 走看看