假设为程序temp.exe,给它发WM_CLOSE消息的时候会弹出来一个“确定”对话框,要不就是窗口被隐藏掉了。
现在想在我的程序启动的时候如果发现系统里有temp.exe存在(通过任务管理器的进程页能看到),就把它无条件终止掉。
请教大家,首先,我如何得到temp.exe(如果它正在运行的话)的句柄,另外,如何静悄悄地把它结束任务呢?
多谢了。

解决方案 »

  1.   

    通过EnumProcesses,EnumProcessModules,GetModuleBaseName得到进程名与temp.exe比较,如果相符则调用TerminateProcess.
      

  2.   

    你有窗口句柄对吧?
    1.GetWindowThreadProcessId
    2.openprocess
    3.TerminateProcess
      

  3.   

    不用WM_CLOSE而用WM_QUIT来试一下webber84(糕鱼昏) 的方法也能用,不过可能太粗鲁哟
      

  4.   

    TerminateProcess is a good way
      

  5.   

    Of couse, TerminateProcess is the best way to forcedly close the  application specified. Nothing bug TerminateProcess can solve your
    request cleanly.