Accidentally found a bug, there is a function is written like this:
void Waitprocexit (DWORD dwpid) {HANDLE hprocess = OpenProcess (process_all_access, 0 if (NULL == hprocess) {DWORD Dwerr = GetLastError (); Printf ( getlasterror=%d.\n Span style= "color: #800000;" > " // do something after the target process Exit // .... return ;}
The function is to wait for the incoming PID process to exit and then perform some business.
However, in some environments execution is not expected.
By GetLastError The result is 5, which is the permission problem.
OpenProcess failed because the process in which the Dwpid is located is Administrator rights, and the process that executes the waitprocexit () function is a user right.
The change code should be modified to:
void waitprocexit (DWORD dwpid) { 0, dwpid); if (NULL = = hprocess) { = GetLastError (); Printf ("getlasterror=%d.\n", Dwerr); } WaitForSingleObject (hprocess,infinite); // Do something after the target process exit // .... return ;}
The Synchronize permission openprocess should be used.
The SYNCHRONIZE description is: The right and the object for synchronization. This enables a thread to wait until the object was in the signaled state.
See also: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684880%28v=vs.85%29.aspx
Bug in waiting for process to end function