User Tools

Site Tools


self_-_elevation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
self_-_elevation [2022/01/13 20:45] – created osoself_-_elevation [2024/10/17 21:42] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 <code powershell> <code powershell>
-     # Self-elevate the script if required+# Self-elevate the script if required
     if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {     if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
-     if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { +        if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { 
-          $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments +            $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments 
-          Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine +            Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine 
-          Exit +            Exit 
-     }+        }
     }     }
 </code> </code>
self_-_elevation.1642106707.txt.gz · Last modified: 2024/10/17 21:42 (external edit)