Self Elevating Version in the Pipeline?

Topics: Archive - General
Oct 21, 2014 at 1:32 PM
Any chance there's a self elevating version of this in the pipeline, possibly using this as the framework:
# Get the ID and security principal of the current user account
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
   # We are running "as Administrator" - so change the title and background color to indicate this
   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
   $Host.UI.RawUI.BackgroundColor = "DarkBlue"
   # We are not running "as Administrator" - so relaunch as administrator
   # Create a new process object that starts PowerShell
   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
   # Specify the current script path and name as a parameter
   $newProcess.Arguments = $myInvocation.MyCommand.Definition;
   # Indicate that the process should be elevated
   $newProcess.Verb = "runas";
   # Start the new process
   # Exit from the current, unelevated, process
# Run your code that needs to be elevated here
Write-Host -NoNewLine "Press any key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

FWIF: Already saw this thread but the method is different.

I'm happy to try this out on my own, but don't know how I would go about creating a new version of Deploy-Application.EXE with the aforementioned snippet.
Oct 21, 2014 at 8:07 PM
The solution you've suggested won't actually elevate silently, it will present a UAC elevation prompt so not much use.
Oct 21, 2014 at 9:28 PM
Thanks for the reply.

I'm already aware that's not silent but I appreciate you pointing that out as as others may be seeing this and thinking it would do that.
I just don't want it to fail if its not run elevated.
Oct 22, 2014 at 8:34 AM
You can configure the toolkit to run without elevation in the XML file but be aware of the caveats mentioned.