BOOL TerminateProcess(
  HANDLE hProcess, // handle to the process
  UINT uExitCode  // exit code for the process
);

解决方案 »

  1.   

    用Application.Terminate就可以了。
      

  2.   

    源代码:
      Delphi Fans共享联盟主页的技巧包裹里面有!
      http://kingron.myetang.com --> Delphi
      

  3.   

    Application.Terminate
    我就是这样控制的
      

  4.   

    我的意思是用本程序强制杀死一个别的程序
    哪怕那个程序的canclose=false
    请问怎样做??
      

  5.   

    FindWindow() // 找到句柄;
    DestroyWindow() 
      

  6.   

    //faint,我的话你没有看到吗?
    我把资料包里面的东西贴出来好了:
    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;
    ********************
    HANDLE hProcess
    Windows NT/2000: The handle must have PROCESS_TERMINATE access. 
    For more information, see Process Security and Access Rights. 所以要先使用 
    DWORD SetSecurityInfo(
      HANDLE handle,                     // handle to object
      SE_OBJECT_TYPE ObjectType,         // object type
      SECURITY_INFORMATION SecurityInfo, // buffer
      PSID psidOwner,                    // new owner SID
      PSID psidGroup,                    // new primary group SID
      PACL pDacl,                        // new DACL
      PACL pSacl                         // new SACL
    );
    上面的代码,即使project2 OnClose:=false也可以强行结束的。
      

  7.   

    谢谢,我看见了,
    不过
    这条语句
    found:=process32first(sshandle,lppe);
    不管我怎样试,found始终为false,不知道为什么
    所以下面的语句都不执行,(注:在我的确运行了一个外部程序的前提下)