UAC via ShellExecute - can't capture stdout

"Scott Zionic" <Scott.Zionic-jo7H/[email protected]>
Newsgroups gmane.comp.windows.off-topic
Message-ID <[email protected]>
I love PowerShell - but I don't love this message:

"The requested operation requires elevation."

For example, "ipconfig /flushdns" requires elevated privileges. I could
use "runas" like so:

runas /user:username "cmd /k ipconfig /flushdns"

But now I'm doing a lot of unnecessary typing and I even have to enter a
password even though the username I pass is the currently logged on user.

I did some googling and came up with what initially appeared to be a
solution:

http://www.peterprovost.org/blog/post/Shifting-Powershell-Arrays.aspx

function elevate
{
   $file, [string]$arguments = $args;
   $psi = new-object System.Diagnostics.ProcessStartInfo $file;
   $psi.Arguments = $arguments;
   $psi.Verb = "runas";
   [System.Diagnostics.Process]::Start($psi);
}

This function uses ShellExecute with the runas verb in order to achieve
much the same result as above but it's much nicer since it doesn't require
all of the extraneous typing. One major problem, though: there is no way
to redirect stdout when launching a process via ShellExecute. So even
though I can use this function with "ipconfig /flushdns", there is no way
to know for sure that the command succeeded since the output is written to
a console window that immediately disappears.

Is there any why to get the functionality of the runas verb without using
ShellExecute?

Scott
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.