在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()都没有反应,也不报错~~
代码如下: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()都没有反应,也不报错~~
那么TerminateProcess 后进程就结束了, 代码就执行不到ShellExecuteEx 这代码
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.