From 2046371f62b81b2de263aee1bbeb71e4482995ef Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 11 Nov 2023 19:09:18 +0000 Subject: [PATCH] fix(windows): downgrade Elevated Privileges error to warn-once (for ssh) --- _webi/install-package.tpl.ps1 | 12 ------------ webi/webi-pwsh.ps1 | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/_webi/install-package.tpl.ps1 b/_webi/install-package.tpl.ps1 index d1b0c57..d027013 100644 --- a/_webi/install-package.tpl.ps1 +++ b/_webi/install-package.tpl.ps1 @@ -3,18 +3,6 @@ $OriginalPath = $Env:Path -function Confirm-IsElevated { - $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() - $p = New-Object System.Security.Principal.WindowsPrincipal($id) - if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) - { Write-Output $true } - else - { Write-Output $false } -} - -if (Confirm-IsElevated) -{ throw "Webi MUST NOT be run with elevated privileges. Please run again as a normal user, NOT as administrator." } - # this allows us to call ps1 files, which allows us to have spaces in filenames # ('powershell "$Env:USERPROFILE\test.ps1" foo' will fail if it has a space in # the path but '& "$Env:USERPROFILE\test.ps1" foo' will work even with a space) diff --git a/webi/webi-pwsh.ps1 b/webi/webi-pwsh.ps1 index 4b4598c..3fa00b7 100644 --- a/webi/webi-pwsh.ps1 +++ b/webi/webi-pwsh.ps1 @@ -24,6 +24,28 @@ $TCmd = "${Esc}[2m${Esc}[35m" $TDim = "${Esc}[2m" $TReset = "${Esc}[0m" +$OriginalPath = $Env:Path +$IsWebiParent = -Not (Test-Path Env:IsWebiChild) +$Env:IsWebiChild = $true + +function Confirm-IsElevated { + $id = [System.Security.Principal.WindowsIdentity]::GetCurrent() + $p = New-Object System.Security.Principal.WindowsPrincipal($id) + if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) + { Write-Output $true } + else + { Write-Output $false } +} + +IF (Confirm-IsElevated) { + IF ($IsWebiParent) { + Write-Host "" + Write-Host "Running Webi with elevated privileges is unsupported." -ForegroundColor Magenta -BackgroundColor black + Write-Host "Please run Webi as a normal user, NOT as administrator." -ForegroundColor Magenta -BackgroundColor black + Write-Host "" + } +} + function Invoke-DownloadUrl { Param ( [string]$URL,