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

  • 相关阅读:
    java泛型
    转载:MSIL Instruction Table
    What if your dynamic sql statement is too long?
    自己第一个正儿八经的div+css页面
    bulk insert formatFile格式记录
    日志 20071221(WCF,using keyword)
    C++点滴
    The scripts used to generate a demo "School" database (with data)
    The typical scenarios of using "Insert" in Tsql
    如何生成任意给定区间的随机值序列
  • 原文地址:https://www.cnblogs.com/findumars/p/7230747.html
Copyright © 2011-2022 走看看