|
1 | 1 | # Self-elevate the script if required
|
2 |
| -if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { |
3 |
| - if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { |
4 |
| - $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments |
5 |
| - Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine |
6 |
| - Exit |
| 2 | +# Get the ID and security principal of the current user account |
| 3 | + $myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() |
| 4 | + $myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) |
| 5 | + |
| 6 | + # Get the security principal for the Administrator role |
| 7 | + $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator |
| 8 | + |
| 9 | + # Check to see if we are currently running "as Administrator" |
| 10 | + if ($myWindowsPrincipal.IsInRole($adminRole)) |
| 11 | + { |
| 12 | + # We are running "as Administrator" |
7 | 13 | }
|
| 14 | + else |
| 15 | + { |
| 16 | + # We are not running "as Administrator" - so relaunch as administrator |
| 17 | + |
| 18 | + # Create a new process object that starts PowerShell |
| 19 | + $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; |
| 20 | + |
| 21 | + # Specify the current script path and name as a parameter |
| 22 | + $newProcess.Arguments = $myInvocation.MyCommand.Definition; |
| 23 | + |
| 24 | + # Indicate that the process should be elevated |
| 25 | + $newProcess.Verb = "runas"; |
| 26 | + |
| 27 | + # Start the new process |
| 28 | + [System.Diagnostics.Process]::Start($newProcess) | Out-Null |
| 29 | + |
| 30 | + # Exit from the current, unelevated, process |
| 31 | + exit |
8 | 32 | }
|
9 | 33 |
|
| 34 | +Set-Location -Path $PSScriptRoot |
| 35 | + |
10 | 36 | Set-ExecutionPolicy Unrestricted -Scope CurrentUser
|
11 | 37 | ls -Recurse *.ps*1 | Unblock-File
|
12 | 38 |
|
13 |
| -Import-Module -DisableNameChecking .\library\Write-Menu.psm1 |
14 |
| -Import-Module .\library\WinCore.psd1 |
15 |
| -Import-Module -DisableNameChecking .\library\PrivacyFunctions.psm1 |
16 |
| -Import-Module -DisableNameChecking .\library\Tweaks.psm1 |
17 |
| -Import-Module -DisableNameChecking .\library\GeneralFunctions.psm1 |
18 |
| -Import-Module -DisableNameChecking .\library\DebloatFunctions.psm1 |
19 |
| -Import-Module -DisableNameChecking .\library\UndoFunctions.psm1 |
| 39 | +Import-Module -DisableNameChecking $PSScriptRoot\library\Write-Menu.psm1 |
| 40 | +Import-Module -DisableNameChecking $PSScriptRoot\library\WinCore.psm1 |
| 41 | +Import-Module -DisableNameChecking $PSScriptRoot\library\PrivacyFunctions.psm1 |
| 42 | +Import-Module -DisableNameChecking $PSScriptRoot\library\Tweaks.psm1 |
| 43 | +Import-Module -DisableNameChecking $PSScriptRoot\library\GeneralFunctions.psm1 |
| 44 | +Import-Module -DisableNameChecking $PSScriptRoot\library\DebloatFunctions.psm1 |
| 45 | +Import-Module -DisableNameChecking $PSScriptRoot\library\UndoFunctions.psm1 |
20 | 46 |
|
21 | 47 | $title = "Windows Toolbox $version"
|
22 | 48 | $host.UI.RawUI.WindowTitle = $title
|
|
441 | 467 | Restart
|
442 | 468 | }
|
443 | 469 | }
|
| 470 | + Read-Host "Press Enter To Continue" |
444 | 471 | } until($mainMenu -eq "ForeverLoop")
|
0 commit comments