Read another process' stdout in C++ Read another process' stdout in C++ windows windows

Read another process' stdout in C++


There's no easy way to do this.

Calling ShellExecuteEx() with the runas verb sends an RPC message to the AppInfo NT Service witch then run the application from an elevated session. There's no API to easily connect the input/output of the elevated process to your application.

Thomas Hruska in his The Code Project article presents his implementation of a CreateProcessElevated() function that solves this.

Instead of running the elevated program directly CreateProcessElevated() relies on another executable that receive the name of the stdin,stdout,stderr named pipes and recreate their handles in the elevated session before calling CreateProcess().


You should replace your use of ShellExecuteEx with CreateProcess. The lpStartupInfo argument lets the std in and std out handles of the process. Just Create an anonymous pipe using CreatePipe that you pass as the arguments. This MSDN article has an example of how to do this.


You need to create a named pipe to the child process. This MSDN article explains with and has code samples.

You should be able to get it going from that.