Guest User

Albert

a guest
Oct 3rd, 2019
230
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# :
  2.     @echo off
  3.     set args=%*
  4. if not defined args goto noargs
  5.     set args=%args:"=`"""%
  6. :noargs
  7.     powershell /nologo /noprofile /command ^
  8.     "&{[ScriptBlock]::Create( '$thisfilename="""%~f0"""' + [Char]10 + ((cat """%~f0""") -join [Char]10) ).Invoke("""%args%""")}"
  9.   exit /b
  10. #>
  11.  
  12. $arch = @{$true="x86";$false="x64"}[$env:Processor_Architecture -eq "x86"]
  13. $thisfile=$thisfilename
  14. $thisdir=split-path $thisfile
  15. $datetime = Get-Date -format yyyy-MM-dd_HH-mm-ss
  16. $caption = split-path $thisfile -leaf
  17.  
  18. function Elevate(){
  19.     $myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
  20.     $myWindowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
  21.     $adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
  22.     if ($myWindowsPrincipal.IsInRole($adminRole)){
  23.         $Host.UI.RawUI.WindowTitle = $thisfile + " (Elevated)"
  24.         clear-host
  25.     }else{
  26.         $newProcess = new-object System.Diagnostics.ProcessStartInfo "cmd.exe";
  27.         $newProcess.Arguments = "/C `"$thisfilename`"";
  28.         $newProcess.Verb = "runas";
  29.         [System.Diagnostics.Process]::Start($newProcess);
  30.         exit
  31.     }
  32. }
  33. Elevate
RAW Paste Data