OpenProcess error 87 invalid parameter

后端 未结 3 1502
攒了一身酷
攒了一身酷 2021-01-21 14:18

I\'m trying to write a program which executes make.exe from MinGW distribution in the current directory and makes use of its STDOUT data and exit code. I have a handle to proces

相关标签:
3条回答
  • 2021-01-21 14:44

    Although the post is old: I noticed that I got ERROR_INVALID_PARAMETER when the process existed, but owned by different user and/or Windows desktop and/or terminal server session.

    Strange enough, the WTSEnumerateProcess() function does not suffer from this error, but is much more expensive, especially on a system that is already under heavy load with many processes (and a call my even exhaust windows kernel resources).

    So, it is not possible to make a 'real' invalid parameter provided and access errors. I would have expected ERROR_ACCESS_DENIED instead (but a task manager invoked as regular/non-elevated user still shows all processes).

    Look like some inconsistencies in Windows?

    0 讨论(0)
  • 2021-01-21 14:45

    You should use the handle from CreateProcess instead of using OpenProcess on the PID.

    OpenProcess only works if the process object still exists. By the time you call OpenProcess if the process object is gone - the result is a call with invalid parameter.

    The success you got with other utilities is either due to a race condition (which may fail some times) or you kept the original handle to the child process open.

    0 讨论(0)
  • 2021-01-21 14:53

    Leaving a tip for someone else's purpose. I managed to reach the ERROR_INVALID_PARAMETER (87) by trying to open:

    • a System process (0)
    • an ID which belonged to a thread, not the process (reference to YatoDev's post).

    The second case may be a problem when you e.g. claim a result from GetWindowThreadProcessId directly, which is an identifier of the thread that created the window, instead of its pointer parameter (which gives you requested PID).

    0 讨论(0)
提交回复
热议问题