From 6f51e0ee692c9ecad77731728c26d2d5af660c6b Mon Sep 17 00:00:00 2001 From: Yannick Meine Date: Mon, 28 Apr 2025 15:40:27 +0200 Subject: [PATCH] everything-alpha: check properly for the existence of the Everything service (fix #2216) In addition to what is described in the linked issue, it also fixes a few other things: - remove the right service during uninstall by using the service name gotten from PowerShell - stop only the processes linked to that application Those fixes are meant to handle a proper cohabitation of different versions of Everything, no matter how many processes or services they each have. --- bucket/everything-alpha.json | 44 ++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/bucket/everything-alpha.json b/bucket/everything-alpha.json index 276b94446ec..a608643b667 100644 --- a/bucket/everything-alpha.json +++ b/bucket/everything-alpha.json @@ -28,16 +28,46 @@ "Set-Content \"$dir\\install-context.reg\" $reg_content -Encoding ASCII" ], "pre_uninstall": [ - "Stop-Process -Name 'everything' -Force -ErrorAction SilentlyContinue", - "if ($(Get-Service -Name Everything -ErrorAction SilentlyContinue).Status -ne 'Stopped') {", - " if (!(is_admin)) { error 'Admin rights are required to stop Everything service'; break }", - " Stop-Service -Name 'Everything' -Force -ErrorAction SilentlyContinue | Out-Null", + "$appPathPattern = (Split-Path $dir -Parent).Replace('\\', '\\\\')", + "", + "$processes = Get-Process -Name 'everything' -ErrorAction SilentlyContinue", + " | Where-Object { $_.Path -match $appPathPattern }", + "info \"Found $($processes.Length) Everything process(es) to stop\"", + "foreach ($process in $processes) {", + " Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue", "}", - "if ((Get-Service -Name Everything -ErrorAction SilentlyContinue) -and ($cmd -eq 'uninstall')) {", - " if (!(is_admin)) { error 'Admin rights are required to remove Everything service'; break }", - " sc.exe delete 'Everything'", + "", + "$services = Get-Service -Name Everything* -ErrorAction SilentlyContinue", + " | Where-Object { $_.BinaryPathName -match $appPathPattern }", + "", + "if ($services.Length -gt 1) {", + " error 'Multiple Everything services found, this is likely a bug with this manifest.'", + " break", + "} elseif ($services.Length -eq 0) {", + " info 'No Everything service found, continuing with uninstall.'", + "} else {", + " $service = $services[0]", + " $serviceName = $service.Name", + " info \"Found Everything service: $serviceName\"", + "", + " if (!(is_admin)) {", + " error 'Administrator rights are required to manage Windows services'", + " break", + " }", + "", + " if ($service.Status -ne 'Stopped') {", + " info 'Stopping service'", + " Stop-Service -Name $serviceName -Force | Out-Null", + " }", + "", + " if ($cmd -eq 'uninstall') {", + " info 'Removing service'", + " sc.exe delete $serviceName", + " }", "}", + "", "if ($cmd -eq 'uninstall') { reg import \"$dir\\uninstall-context.reg\" }", + "", "Get-ChildItem \"$dir\\*\" -Include 'Bookmarks*.csv', 'Everything.lng', 'Everything*.db', 'Everything*.ini', 'Filters*.csv', 'Plugins*.ini', 'Run History*.csv', 'Search History*.csv' | Copy-Item -Destination \"$persist_dir\" -ErrorAction SilentlyContinue -Force" ], "bin": "Everything.exe",