We tried to write a replacement for the Win32 _popen() function using CreatePipe() (see https://nrubsig.kpaste.net/b9 for the code).
It works as a standalone application, but if we embed it into our software (filesystem driver, where threads impersonate the users which access the filesystem), it fails with ERROR_BAD_IMPERSONATION_LEVEL (1346) for the "SYSTEM" user.