Skip to content

Commit 6f51e0e

Browse files
committed
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.
1 parent b9ca60b commit 6f51e0e

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

bucket/everything-alpha.json

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,46 @@
2828
"Set-Content \"$dir\\install-context.reg\" $reg_content -Encoding ASCII"
2929
],
3030
"pre_uninstall": [
31-
"Stop-Process -Name 'everything' -Force -ErrorAction SilentlyContinue",
32-
"if ($(Get-Service -Name Everything -ErrorAction SilentlyContinue).Status -ne 'Stopped') {",
33-
" if (!(is_admin)) { error 'Admin rights are required to stop Everything service'; break }",
34-
" Stop-Service -Name 'Everything' -Force -ErrorAction SilentlyContinue | Out-Null",
31+
"$appPathPattern = (Split-Path $dir -Parent).Replace('\\', '\\\\')",
32+
"",
33+
"$processes = Get-Process -Name 'everything' -ErrorAction SilentlyContinue",
34+
" | Where-Object { $_.Path -match $appPathPattern }",
35+
"info \"Found $($processes.Length) Everything process(es) to stop\"",
36+
"foreach ($process in $processes) {",
37+
" Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue",
3538
"}",
36-
"if ((Get-Service -Name Everything -ErrorAction SilentlyContinue) -and ($cmd -eq 'uninstall')) {",
37-
" if (!(is_admin)) { error 'Admin rights are required to remove Everything service'; break }",
38-
" sc.exe delete 'Everything'",
39+
"",
40+
"$services = Get-Service -Name Everything* -ErrorAction SilentlyContinue",
41+
" | Where-Object { $_.BinaryPathName -match $appPathPattern }",
42+
"",
43+
"if ($services.Length -gt 1) {",
44+
" error 'Multiple Everything services found, this is likely a bug with this manifest.'",
45+
" break",
46+
"} elseif ($services.Length -eq 0) {",
47+
" info 'No Everything service found, continuing with uninstall.'",
48+
"} else {",
49+
" $service = $services[0]",
50+
" $serviceName = $service.Name",
51+
" info \"Found Everything service: $serviceName\"",
52+
"",
53+
" if (!(is_admin)) {",
54+
" error 'Administrator rights are required to manage Windows services'",
55+
" break",
56+
" }",
57+
"",
58+
" if ($service.Status -ne 'Stopped') {",
59+
" info 'Stopping service'",
60+
" Stop-Service -Name $serviceName -Force | Out-Null",
61+
" }",
62+
"",
63+
" if ($cmd -eq 'uninstall') {",
64+
" info 'Removing service'",
65+
" sc.exe delete $serviceName",
66+
" }",
3967
"}",
68+
"",
4069
"if ($cmd -eq 'uninstall') { reg import \"$dir\\uninstall-context.reg\" }",
70+
"",
4171
"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"
4272
],
4373
"bin": "Everything.exe",

0 commit comments

Comments
 (0)