开发者

How to check if a given process is running when having its handle

开发者 https://www.devze.com 2023-03-15 21:13 出处:网络
I am using ShellExecuteEx to start an application. After successful start im reading TShellExecuteInfo.hProcess to obtain a handle of the started process.

I am using ShellExecuteEx to start an application. After successful start im reading TShellExecuteInfo.hProcess to obtain a handle of the started process.

I would like to periodically check if the process started by my application is still running. Two or more processess with the same name can run simultaneously and I want to be sure that my application is checking the correct process.

I want to be able to do this on Windows sy开发者_JS百科stems from Windows 2000 to above.

I know that there is WinAPI function GetProcessId which is doing exactly what I want but it does not support Windows 2000.

Thank you for your answers.


Call WaitForSingleObject on that handle, and use a timeout parameter of zero. If the process is still running, the function will return Wait_Timeout; if the process has terminated, then it will return Wait_Object_0 (because process termination causes its handles to become signaled.)

If you want to know what the exit status of the process is, then call GetExitCodeProcess.

0

精彩评论

暂无评论...
验证码 换一张
取 消