How to check if a given process works if it has a handle

I am using ShellExecuteEx to run the application. After successfully starting im reading TShellExecuteInfo.hProcess to get the handle of the process started.

I would like to periodically check if the process started by my application is running. Two or more processions with the same name can be executed at the same time, and I want to be sure that my application checks the correct process.

I want this to be possible on Windows systems from Windows 2000 to above.

I know that there is a WinAPI GetProcessId function that does exactly what I want, but does not support Windows 2000.

Thank you for your responses.

+6
source share
1 answer

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

If you want to know what the process completion status is, call GetExitCodeProcess .

+14
source

Source: https://habr.com/ru/post/891450/


All Articles