dll中用TerminateProcess关闭进程后无法再打开该exe文件了?

osiku 2008-04-23 02:28:18
在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()都没有反应,也不报错~~
...全文
116 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
美丽海洋 2008-04-23
  • 打赏
  • 举报
回复
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.

cnzdgs 2008-04-23
  • 打赏
  • 举报
回复
TerminateProcess函数只有失败时才会返回。
Yofoo 2008-04-23
  • 打赏
  • 举报
回复
按键的焦点窗体 是否是 ::TerminateProcess( hProcessHandle, 4 ); 这个进程, 如果是的
那么TerminateProcess 后进程就结束了, 代码就执行不到ShellExecuteEx 这代码

15,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧