Thank you very much for writing Win32::RunAsAdmin. The one thing I needed which it didn't do was to wait for the elevated process to finish running. I came up with the following Powershell incantation to do that and pass the exit code of the elevated process back:
# Run a process in an elevated window, wait for its exit
sub win32_run_elevated {
my( $exe, @args ) = @_;
my $args = join " ", map { if(/[ "]/) { s!"!\\"!g; qq{"$_"} } else
+ { $_ }} @args;
my $ps1 = sprintf q{powershell -NonInteractive -NoProfile -Command
+ "$process = Start-Process '%s' -PassThru -ErrorAction Stop -Argument
+List '%s' -Verb RunAs -Wait; Exit $process.ExitCode"},
$exe, $args;
$ps1
}
I haven't dug deep enough into Application.Process to know whether it can wait for the elevated child as well, and as my target environment has Powershell enabled anyway, using another level of indirection isn't a hurdle for me.