杀进程除了用TerminateProcess外还可以用什么方法,欢迎大家提供别的方法。

解决方案 »

  1.   

    有些肯定不好:
    ExitProcess
    向进程发送WM_Close消息
      

  2.   

    昨天看电脑高手合订本有个杀非本地进程
    c的
    改为delphi的function SafeClose(hProcess: THandle; uExitCode: UINT): BOOL;
    var
      dwTID, dwCode, dwErr: DWORD;
      hProcessDup, hRT: THandle;
      hKernel, hP: THandle;
      bDup, bSuccess: BOOL;
      pfnExitProc: FARPROC;
    begin
      dwErr := 0;
      hProcessDup := INVALID_HANDLE_VALUE;
      hRT := 0;
      bSuccess := False;  hKernel := GetModuleHandle('Kernel32');
      bDup := DuplicateHandle(GetCurrentProcess, hProcess, GetCurrentProcess,
                              @hProcessDup, PROCESS_ALL_ACCESS, False, 0);  if bDup then
        hP := hProcessDup
      else
        hP := hProcess;
      if GetExitCodeProcess(hP, dwCode) and (dwCode = STILL_ACTIVE) then
      begin
        pfnExitProc := GetProcAddress(hKernel, 'ExitProcess');
        hRT := CreateRemoteThread(hP, nil, 0, pfnExitProc, @uExitCode, 0,
                                  dwTID);
        if hRt = 0 then
          dwErr := GetLastError;
      end
      else
         dwErr := ERROR_PROCESS_ABORTED;  if hRT <> 0 then
      begin
        WaitForSingleObject(hP, INFINITE);
        CloseHandle(hRT);
        bSuccess := TRUE;
      end;  if bDup then
        CloseHandle(hProcessDup);  if not bSuccess then
        SetLastError(dwErr);
      Result := bSuccess;
    end;