You have initialized the cbSize
field of your STARTUPINFO
structure, but you've left the rest uninitialized. The first time you call CreateProcess
, the uninitialized values are evidently so wrong that the function recognizes that they're wrong and gives up. You were lucky.
The second time you call it, the values are apparently such that the CreateProcess
thinks you have asked it to do something it knows how to do, and so it proceeds. Such is the nature of undefined behavior.
To fix this, initialize all of the struct:
STARTUPINFO si = {sizeof(STARTUPINFO)};