powershell:powershell_mit_erweiterten_rechten_im_script_starten
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
powershell:powershell_mit_erweiterten_rechten_im_script_starten [2017/03/30 13:26] – ronny | powershell: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:// | ||
<code Powershell> | <code Powershell> | ||
- | # Get the ID and security principal of the current user account | + | $myScript = { |
- | $myWindowsID=[System.Security.Principal.WindowsIdentity]:: | + | get-childitem >> c: |
- | $myWindowsPrincipal=new-object | + | } |
+ | $newProcess | ||
+ | $newProcess.Arguments = $myScript | ||
+ | $newProcess.Verb | ||
+ | [System.Diagnostics.Process]:: | ||
+ | </ | ||
- | # Get the security principal for the Administrator | + | Dieses Script startet eine neue Powershell in einem separaten Prozess, die über ein volles |
- | $adminRole=[System.Security.Principal.WindowsBuiltInRole]:: | + | |
- | # Check to see if we are currently running "as Administrator" | + | Quelle: [[https:// |
- | if ($myWindowsPrincipal.IsInRole($adminRole)) | + | |
- | { | + | |
- | # We are running "as Administrator" | + | |
- | $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + " | + | |
- | | + | |
- | clear-host | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | # We are not running "as Administrator" | + | |
- | # Create a new process object that starts PowerShell | + | |
- | | + | |
- | # Specify the current | + | |
- | | + | |
- | # Indicate that the process should be elevated | + | |
- | | + | |
- | # Start the new process | + | {{tag>[Powershell Elevated]}} |
- | [System.Diagnostics.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(" | + | |
- | </ | + |
powershell/powershell_mit_erweiterten_rechten_im_script_starten.1490873217.txt.gz · Zuletzt geändert: 2017/03/30 13:26 von ronny