From 855be8de9c6a26f5d741a2dd72189eda13adee7b Mon Sep 17 00:00:00 2001 From: Tomas Kracmar Date: Wed, 29 Jul 2026 11:49:47 +0200 Subject: [PATCH] fix(Uninstall): use script location, fix broken self-delete Two bugs in Uninstall-Elysium: - $ElysiumPath came from Get-Location (the caller's current working directory) instead of $PSScriptRoot. Running the script from any CWD other than the install folder recursively force-deleted the wrong directory. - The self-delete workaround was also broken: Remove-Item -Exclude matches leaf names via wildcard, not the full path it was given, so the exclusion never matched; and the deferred "powershell.exe -Command -ArgumentList " command line is not valid syntax for binding $path in the child process. PowerShell reads a script fully into memory before running it, so it holds no open handle on the file - deleting the install directory (including this script) while it's still executing is safe. Dropped the exclude/deferred-process workaround entirely. Co-Authored-By: Claude Sonnet 5 --- Uninstall.ps1 | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Uninstall.ps1 b/Uninstall.ps1 index 4951a4a..1c73ba0 100644 --- a/Uninstall.ps1 +++ b/Uninstall.ps1 @@ -41,26 +41,20 @@ function Start-UninstallTranscript { function Stop-UninstallTranscript { try { Stop-Transcript | Out-Null } catch {} } function Uninstall-Elysium { - $ElysiumPath = Get-Location + $ElysiumPath = $PSScriptRoot Write-Host "Uninstalling Elysium tool from $ElysiumPath..." # Check if the Elysium directory exists if (Test-Path $ElysiumPath) { - # Schedule the script file for deletion - $scriptPath = $MyInvocation.MyCommand.Path - $deleteScript = { param($path) Remove-Item -Path $path -Force } - Start-Sleep -Seconds 3 # Delay to ensure the script finishes - Start-Process -FilePath "powershell.exe" -ArgumentList "-Command", $deleteScript, "-ArgumentList", $scriptPath -WindowStyle Hidden - - # Remove the Elysium directory and all its contents - Remove-Item -Path $ElysiumPath -Recurse -Force -Exclude $scriptPath - Write-Host "Elysium tool and all related files have been removed, excluding this script. This script will be deleted shortly." + # PowerShell reads the whole script into memory before execution begins, so it holds no + # open file handle on this script - deleting the install directory (including this file) + # while still running is safe and needs no deferred external delete process. + Remove-Item -Path $ElysiumPath -Recurse -Force + Write-Host "Elysium tool and all related files have been removed." } else { Write-Host "Elysium directory not found. It might have been removed already, or the path is incorrect." } - - # Additional cleanup actions can be added here if needed } Start-UninstallTranscript