From ae57539640a9086f35e2da3ac992127184898372 Mon Sep 17 00:00:00 2001 From: Chris Titus Date: Wed, 14 Aug 2024 14:54:34 -0500 Subject: [PATCH] admin titus version --- scripts/start.ps1 | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scripts/start.ps1 b/scripts/start.ps1 index 73693260..443b7b15 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -44,15 +44,26 @@ $sync.version = "#{replaceme}" $sync.configs = @{} $sync.ProcessRunning = $false -# 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 +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Output "Winutil needs to be run as Administrator. Attempting to relaunch." + + $wtInstalled = Get-Command wt.exe -ErrorAction SilentlyContinue + $pwshInstalled = Get-Command pwsh -ErrorAction SilentlyContinue + if ($pwshInstalled) { + $powershellcmd = "pwsh" + } else { + $powershellcmd = "powershell" + } + + if ($wtInstalled) { + Start-Process wt.exe -ArgumentList "new-tab $powershellcmd -ExecutionPolicy Bypass -Command `"irm https://christitus.com/win | iex`"" -Verb RunAs + } else { + Start-Process $powershellcmd -ArgumentList "-ExecutionPolicy Bypass -Command `"irm https://christitus.com/win | iex`"" -Verb RunAs + } + break } # Set PowerShell window title $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)" -clear-host +clear-host \ No newline at end of file