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.
Follow the simple guidelines for checking if a process is running or not. They are as such pinfo = proc. as_dict (attrs= [‘pid’, ‘name’, ‘create_time’]) except (psutil.NoSuchProcess, psutil.AccessDenied , psutil.ZombieProcess) :
If you have a process identifier, you can get the process handle by calling the OpenProcess function. OpenProcess enables you to specify the handle's access rights and whether it can be inherited. A process can use the GetCurrentProcess function to retrieve a pseudo handle to its own process object.
Once checkIfProcessRunning returns False, it sets chromeRunning = False to exit the while loop and continue with the rest of the program. You need to determine the process name you’re checking.
pinfo = proc. as_dict (attrs= [‘pid’, ‘name’, ‘create_time’]) except (psutil.NoSuchProcess, psutil.AccessDenied , psutil.ZombieProcess) : To check if a process is running or not we will iterate over all the running processes using psutil.process_iter () and during iteration match the process name.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With