简体   繁体   中英

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

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 systems 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM