From b1c27a982bf68e371df6b6b273d390a16a2c760d Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 8 Jun 2023 18:04:03 +0200 Subject: [PATCH] Refactor LGHUB backup --- scripts/Windows/Software/LGHub/Manage.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/Windows/Software/LGHub/Manage.ps1 b/scripts/Windows/Software/LGHub/Manage.ps1 index e52843c8..11176d65 100644 --- a/scripts/Windows/Software/LGHub/Manage.ps1 +++ b/scripts/Windows/Software/LGHub/Manage.ps1 @@ -6,14 +6,18 @@ $null = New-Module { function Invoke-BackupLGHub([Context] $context) { $hubName = "lghub.exe"; - $mainProcesses = Get-Process | Where-Object { [System.IO.Path]::GetFileName($_.Path) -eq "$hubName" }; - $lghub = $mainProcesses[0].Path; - $hubProcesses = ($mainProcesses + (Get-Process | Where-Object { @("$hubName", "lghub_", "lghub_system_tray.exe") -contains [System.IO.Path]::GetFileName($_.Path) })); - $hubProcesses | Foreach-Object { $_.Kill() }; + + $mainProcess = Get-Process | Where-Object { + [System.IO.Path]::GetFileName($_.Path) -eq "$hubName" -and + $_.Parent.ProcessName -eq "explorer" + }; + + $lghub = $mainProcess.Path; + $mainProcess | Foreach-Object { $_.Kill($true) }; $context.Backup($path, $context.SoftwareArchive($softwareName), @("-i!settings.db", "-i!icon_cache")); if ($lghub) { - & "$lghub"; + Start-Process $lghub; } } }