From e8d79c9d3873e699d06cfa6727eca68543791d2e Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Fri, 9 Jul 2021 22:29:10 +0200 Subject: [PATCH] Warn when powershell script is run as admin Fixes #163 --- bootstrap-haskell.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bootstrap-haskell.ps1 b/bootstrap-haskell.ps1 index 7a7cbce..063abf8 100644 --- a/bootstrap-haskell.ps1 +++ b/bootstrap-haskell.ps1 @@ -150,6 +150,15 @@ function Exec $ErrorActionPreference = 'Stop' +$elevated = ([Security.Principal.WindowsPrincipal] ` + [Security.Principal.WindowsIdentity]::GetCurrent() +).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) + +if ($elevated) { + Print-Msg -color Yellow -msg ('This script should not be run as administrator/elevated. Waiting 10s before continuing anyway...') + Start-Sleep -s 10 +} + $GhcupBasePrefixEnv = [System.Environment]::GetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'user') if ($GhcupBasePrefixEnv) {