From eec184ee81c5e4140c9a58db1595f9bb8f2ff187 Mon Sep 17 00:00:00 2001 From: Hayden Plumley Date: Sat, 11 May 2024 13:48:18 -0700 Subject: [PATCH] Simplified Admin Check and Added Code Comments (#1938) - Simplified the admin check by filtering the "WindowsIdentity" class for owner value and comparing against admin value - Removed the need for an if admin check by moving its commands under the if not admin check. - Added code comments --- scripts/start.ps1 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/scripts/start.ps1 b/scripts/start.ps1 index a2b65b01..4f68920a 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -44,21 +44,16 @@ $sync.version = "#{replaceme}" $sync.configs = @{} $sync.ProcessRunning = $false -$currentPid = [System.Security.Principal.WindowsIdentity]::GetCurrent() -$principal = new-object System.Security.Principal.WindowsPrincipal($currentPid) -$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator - - -if ($principal.IsInRole($adminRole)) -{ - $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)" - clear-host -} -else +# If script isn't running as admin, show error message and quit +If (([Security.Principal.WindowsIdentity]::GetCurrent()).Owner.Value -ne "S-1-5-32-544") { Write-Host "===========================================" -Foregroundcolor Red Write-Host "-- Scripts must be run as Administrator ---" -Foregroundcolor Red Write-Host "-- Right-Click Start -> Terminal(Admin) ---" -Foregroundcolor Red Write-Host "===========================================" -Foregroundcolor Red break -} \ No newline at end of file +} + +# Set PowerShell window title +$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)" +clear-host