Benutzer-Werkzeuge

Webseiten-Werkzeuge


powershell:powershell_mit_erweiterten_rechten_im_script_starten

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
powershell:powershell_mit_erweiterten_rechten_im_script_starten [2017/03/30 13:24] – angelegt ronnypowershell:powershell_mit_erweiterten_rechten_im_script_starten [2017/03/30 14:00] (aktuell) ronny
Zeile 1: Zeile 1:
 ====== Powershell mit erweiterten Rechten im Script starten ====== ====== Powershell mit erweiterten Rechten im Script starten ======
- 
-[[https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/09/23/a-self-elevating-powershell-script/]] 
  
 <code Powershell> <code Powershell>
-# Get the ID and security principal of the current user account+$myScript = { 
 + get-childitem >> c:\windows\out.txt 
 +
 +$newProcess = New-Object System.Diagnostics.ProcessStartInfo "Powershell"; 
 +$newProcess.Arguments = $myScript 
 +$newProcess.Verb = "runas" 
 +[System.Diagnostics.Process]::Start($newProcess) 
 +</code>
  
-$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()+Dieses Script startet eine neue Powershell in einem separaten Prozess, die über ein volles Administrator-Token verfügt ((Solange das Windows-Konto selbst natürlich Adminrechte hat, andernfalls fragt Windows natürlich nach)).
  
-$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)+Quelle: [[https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/09/23/a-self-elevating-powershell-script/]]
  
-  +{{tag>[Powershell Elevated]}}
- +
-# Get the security principal for the Administrator role +
- +
-$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator +
- +
-  +
- +
-# 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" +
- +
-   clear-host +
- +
-   } +
- +
-else +
- +
-   { +
- +
-   # 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 +
- +
-   [System.Diagnostics.Process]::Start($newProcess); +
- +
-    +
- +
-   # Exit from the current, unelevated, process +
- +
-   exit +
- +
-   } +
- +
-  +
- +
-# Run your code that needs to be elevated here +
- +
-Write-Host -NoNewLine "Press any key to continue..." +
- +
-$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown"+
-</code>+
powershell/powershell_mit_erweiterten_rechten_im_script_starten.txt · Zuletzt geändert: 2017/03/30 14:00 von ronny

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki