In Windows, is there a way to launch a process in C++ and then read what it spat out into stdout when it's done? The process must be run using elevated privileges (on Vista or later) if necessary.
I'm currently using ShellExecuteEx() to launch the process and running a while-loop until GetExitCodeProcess() no longer returns STILL_ACTIVE via the lpExitCode parameter (with a WaitForSingleObject() call doing a 100 msec wait during each iteration).
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With