From 841eb454ed21c39d8158443dece46eec0af8e719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20W=C3=B3jcik?= <34631176+emilwojcik93@users.noreply.github.com> Date: Sat, 1 Mar 2025 14:03:16 +0100 Subject: [PATCH] Update start.ps1 fix logic of permissions elevation process --- scripts/start.ps1 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/start.ps1 b/scripts/start.ps1 index c289709c..66bb7a3b 100644 --- a/scripts/start.ps1 +++ b/scripts/start.ps1 @@ -39,6 +39,7 @@ $sync.version = "#{replaceme}" $sync.configs = @{} $sync.ProcessRunning = $false + 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." $argList = @() @@ -46,21 +47,23 @@ if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]: $PSBoundParameters.GetEnumerator() | ForEach-Object { $argList += if ($_.Value -is [switch] -and $_.Value) { "-$($_.Key)" + } elseif ($_.Value -is [array]) { + "-$($_.Key) $($_.Value -join ',')" } elseif ($_.Value) { - "-$($_.Key) `"$($_.Value)`"" + "-$($_.Key) '$($_.Value)'" } } - - $script = if ($MyInvocation.MyCommand.Path) { - "& { & '$($MyInvocation.MyCommand.Path)' $argList }" + + $script = if ($PSCommandPath) { + "& { & `"$($PSCommandPath)`" $($argList -join ' ') }" } else { - "iex '& { $(irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1) } $argList'" + "&([ScriptBlock]::Create((irm https://github.com/ChrisTitusTech/winutil/releases/latest/download/winutil.ps1))) $($argList -join ' ')" } - + $powershellcmd = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh" } else { "powershell" } $processCmd = if (Get-Command wt.exe -ErrorAction SilentlyContinue) { "wt.exe" } else { $powershellcmd } - - Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command $script" -Verb RunAs + + Start-Process $processCmd -ArgumentList "$powershellcmd -ExecutionPolicy Bypass -NoProfile -Command `"$script`"" -Verb RunAs break }