您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Delphi >> 高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。

高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。

来源:网络整理     时间:2016/8/25 23:20:41     关键词:

关于网友提出的“ 高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。”问题疑问,本网通过在网上对“ 高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。
描述:

程序如下:
procedure TForm1.Button1Click(Sender: TObject);
var
  proc: procobject;
  procHandle: THandle;
  ExitCD: integer;
// This does a "hard" kill. From the MS help file :
// The TerminateProcess function is used to unconditionally cause a process to exit.
// Use it only in extreme circumstances. The state of global data maintained by dynamic-link
// Libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.
// TerminateProcess causes all threads within a process to terminate, and causes a process
// to exit, but DLLs attached to the process are not notified that the process is terminating.
begin
  screen.Cursor := crhourglass;
  ExitCD := 0;
  if listbox1.itemindex <> -1 then
    begin
      proc := procObject(listbox1.items.objects[listbox1.itemindex]); // get handle
      procHandle := 0;
      try
        TerminateApp(int64(Proc.Theproc.th32ProcessID), 1000);
        // Í¨¹ýÒÔÏÂ2ÐдúÂëÒ²¿ÉÒÔɱ½ø³Ì£¬µ«ÊÇÎÞ·¨É±Ò»Ð©ÏµÍ³½ø³ÌµÈ¸ß¼¶È¨Ï޵Ľø³Ì£¬
        //¸ü¶à±ê×¼ÇëÕÒMSDNÖ÷Ì⣺HOWTO: Terminate an Application "Cleanly" in Win32
        //»òÕß·ÃÎÊÕâÀhttp://support.microsoft.com/default.aspx?scid=kb;EN-US;q178893
        //procHandle := OpenProcess(PROCESS_TERMINATE, false, Proc.Theproc.th32ProcessID);
        //TerminateProcess(procHandle, ExitCd);
      except
        showmessage('An error has occurred while trying to kill the selected application.' +
          #13 + 'Error code :' + inttostr(ExitCD));
      end;
      if procHandle <> 0 then
        CloseHandle(procHandle);
    end;
  if ExitCD = 0 then
    begin
      // wait for windows to kill the task before refreshing the app list
      sleep(200);
      lookforexes;                  // refresh the process list
      screen.cursor := crDefault;
    end;
end;
。。。
function TerminateAppEnum(hwnd: HWND; lParam: LPARAM): boolean; stdcall;
var
  dwID: DWORD;
begin
  GetWindowThreadProcessId(hwnd, @dwID) ;
  if(dwID = lParam) then
     PostMessage(hwnd, WM_CLOSE, 0, 0) ;
  Result:= TRUE;
end;
function TerminateApp(dwPID: DWORD ; dwTimeout: DWORD): DWORD;
var
  hProc: THANDLE;
  dwRet: DWORD;
begin
  // If we can't open the process with PROCESS_TERMINATE rights,
  // then we give up immediately.
  {
  hProc := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, FALSE,
     dwPID);
  }
  hProc := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, true,
     (dwPID));
  if(hProc = 0) then
     Result:= TA_FAILED;
  // TerminateAppEnum() posts WM_CLOSE to all windows whose PID
  // matches your process's.
  EnumWindows(@TerminateAppEnum, dwPID) ;
  // Wait on the handle. If it signals, great. If it times out,
  // then you kill it.
  if(WaitForSingleObject(hProc, dwTimeout) <> WAIT_OBJECT_0) then
  begin
    if TerminateProcess(hProc,0) then
      dwRet:= TA_SUCCESS_KILL
    else
    dwRet:= 0;
  end else
     dwRet := TA_SUCCESS_CLEAN ;
  CloseHandle(hProc) ;
  Result:= dwRet ;
end;


解决方案1:

眼花

解决方案2:

upup

解决方案3:

up up

解决方案4:

呵呵,不太懂com之类的。现在在学校旁边的网吧,星期六回去后试试

解决方案5:

直接去找“爱的眼睛”或“清洁工门诊”大哥帮帮忙,实在是不会,帮你顶顶


以上介绍了“ 高手指教:如何杀死一个com组件里面创建的excel进程,我写程序了,杀别的都行,就是杀不掉com里创建的excel进程。”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3593164.html

相关图片

相关文章