首先你需要找到这个应用程序的句柄,通过FindWindow等方法可以获得;然后你在给他发送一个要求关闭的消息比如WM_CLOSE等等。

解决方案 »

  1.   

    uses tlhelp32;
    假设要终止的程序的文件名为:project2.exe,那么例程如下:
    var
    lppe:tprocessentry32;
    sshandle:thandle;
    hh:hwnd;
    found:boolean;
    begin
    sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);
    found:=process32first(sshandle,lppe);
    while found do
    begin
      //进行你的处理其中lppe.szExefile就是程序名。
      if uppercase(extractfilename(lppe.szExeFile))='PROJECT2.EXE' then
      begin
        hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);
        TerminateProcess(hh,0);
      end;
      found:=process32next(sshandle,lppe);
    end;
    end;
      

  2.   

    var MyHandle:THandle;
    begin
     MyHandle:=FindWindow(nil,'Project name');
     if MyHandle<>0 then
      DestroyWindow(MyHandle);
    end;