From 35009cea981676903561b0778f1c8b0050b5c8b2 Mon Sep 17 00:00:00 2001 From: LoganDark Date: Tue, 11 May 2021 19:29:00 +0200 Subject: [PATCH] Fix script allowing itself to run as admin --- InstallWSL.psm1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/InstallWSL.psm1 b/InstallWSL.psm1 index dccc729..a7a58fe 100644 --- a/InstallWSL.psm1 +++ b/InstallWSL.psm1 @@ -334,6 +334,10 @@ function Install-WSLInteractive { $Menu = 'main' + if ([Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544') { + $Menu = 'admin' + } + while ($Menu -ne 'exit') { Clear-Host # 80 chars: ' ' @@ -465,6 +469,15 @@ function Install-WSLInteractive { $Host.UI.ReadLine() $Menu = 'main' } + 'admin' { + Write-Output '' + Write-Host ' !! This script should NOT be run as Administrator' -ForegroundColor Red + Write-Host ' !! Please close this window and run the script normally' -ForegroundColor Red + Write-Output '' + Write-Host ' Press enter to continue...' -NoNewLine + $Host.UI.ReadLine() + $Menu = 'exit' + } default { Write-Output '' Write-Host " !! Invalid menu encountered ($Menu). Exiting" -ForegroundColor Red