我在程序中调用shellexecute()运行了一个外部程序snort.exe,该程序运行在dos窗口中,现要在我的程序中中止该snort.exe的运行,我试图用sendmessage()来关闭该窗口,但是弹出一条信息提示说windows无法关闭该窗口,是否强行关闭,当然我选择“是”可以关闭该窗口,但是我想知道有没有别的方法可以一步到位,直接关闭该窗口,恳请帮忙。

解决方案 »

  1.   

    先得到snort.exe的进程ID在用进程中断结束!
      

  2.   

    我想你一定保留它的句柄是吧
    那你就可以用TerminateProcess 强制结束进程的方式来结束应用程序呀:The TerminateProcess function terminates the specified process and all of its threads. BOOL TerminateProcess(    HANDLE hProcess, // handle to the process 
        UINT uExitCode  // exit code for the process  
       );
     ParametershProcessIdentifies the process to terminate. 
    Windows NT: The handle must have PROCESS_TERMINATE access. For more information, see Process Objects. uExitCodeSpecifies the exit code for the process and for all threads terminated as a result of this call. Use the GetExitCodeProcess function to retrieve the process's exit value. Use the GetExitCodeThread function to retrieve a thread's exit value.
      

  3.   

    handle : = FindWindows()......;
    SendMessage(handle,WM_CLOSE,0,0);