在dll的键盘钩子程序中关闭了指定的程序后,就无法再启动此exe文件了。但把代码放到界面中运行却能正常启动。
代码如下:LRESULT WINAPI CallBackKeyMsgProc(int code, WPARAM wParam, LPARAM lParam)
{  if (HC_ACTION == code || HC_NOREMOVE == code)
{
  if (wParam==VK_F9)
{
 
HANDLE hProcessHandle;  
ULONG nProcessID; 
HWND hwnd=NULL;
hwnd=::FindWindowEx(NULL,NULL,NULL,"电信缴费程序");
if(hwnd!=NULL)
{
::GetWindowThreadProcessId( hwnd, &nProcessID ); 
hProcessHandle = ::OpenProcess( PROCESS_TERMINATE, FALSE,nProcessID );
::TerminateProcess( hProcessHandle, 4 ); SHELLEXECUTEINFO shell = { sizeof(shell)};
shell.fMask = SEE_MASK_FLAG_DDEWAIT;
shell.lpVerb = "open";
shell.lpFile ="D:\\TSoft\\telecom.exe";
shell.nShow = SW_SHOWNORMAL;
::ShellExecuteEx(&shell) ;
 

} }
 
      return(CallNextHookEx(NULL,code,wParam,lParam));
}
用过::CreateProcess和system()都没有反应,也不报错~~

解决方案 »

  1.   

    按键的焦点窗体 是否是 ::TerminateProcess( hProcessHandle, 4 ); 这个进程, 如果是的
    那么TerminateProcess 后进程就结束了, 代码就执行不到ShellExecuteEx 这代码
      

  2.   

    TerminateProcess函数只有失败时才会返回。
      

  3.   

    Terminating a process causes the following: All of the object handles opened by the process are closed. 
    All of the threads in the process terminate their execution. 
    The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate. 
    The states of all threads of the process become signaled, satisfying any threads that had been waiting for the threads to terminate. 
    The termination status of the process changes from STILL_ACTIVE to the exit value of the process. 
    Terminating a process does not cause child processes to be terminated. Terminating a process does not necessarily remove the process object from the system. A process object is deleted when the last handle to the process is closed.