From 0747b59eb27d6273a092f88f4e2c716186fa37e5 Mon Sep 17 00:00:00 2001 From: Xyueta Date: Sat, 21 Oct 2023 22:32:58 +0200 Subject: [PATCH] feat: revamp services/process termination --- .../AtlasDesktop/1. Software/Remove Edge.ps1 | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/playbook/Executables/AtlasDesktop/1. Software/Remove Edge.ps1 b/src/playbook/Executables/AtlasDesktop/1. Software/Remove Edge.ps1 index a31e365465..cfea38bc3a 100644 --- a/src/playbook/Executables/AtlasDesktop/1. Software/Remove Edge.ps1 +++ b/src/playbook/Executables/AtlasDesktop/1. Software/Remove Edge.ps1 @@ -37,6 +37,9 @@ $ProgressPreference = "SilentlyContinue" $user = $env:USERNAME $SID = (New-Object System.Security.Principal.NTAccount($user)).Translate([Security.Principal.SecurityIdentifier]).Value +$services = (Get-Service -Name "*CDP*" | Where-Object {$_.Status -eq "Running"}).Name +$processes = (Get-Process | Where-Object {($_.Path -like "$env:SystemDrive\Program Files (x86)\Microsoft\*") -or ($_.Name -like "*edge*")}).Id + if ($Exit -and ((-not $UninstallAll) -and (-not $UninstallEdge))) { $Exit = $false } @@ -63,10 +66,9 @@ function DeleteEdgeUpdate { Unregister-ScheduledTask -TaskName "MicrosoftEdgeUpdateTaskMachineCore" -Confirm:$false | Out-Null Unregister-ScheduledTask -TaskName "MicrosoftEdgeUpdateTaskMachineUA" -Confirm:$false | Out-Null - # remove all Edge services + # delete edge services foreach ($service in $services) { - Stop-Service -Name $service -Force - sc.exe delete $service | Out-Null + sc.exe delete $service } # delete the Edge Update folder @@ -80,10 +82,13 @@ function RemoveEdgeChromium { $baseKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft" $ErrorActionPreference = 'SilentlyContinue') - # Terminate Edge processes - Get-Process | Where-Object {$_.Path -like "$env:SystemDrive\Program Files (x86)\Microsoft\*"} | ForEach-Object {Stop-Process -Id $_.Id -Force} - Get-Process -Name "*edge*" | Stop-Process -Force - Get-Service -Name "*edge*" | Stop-Service -Force + # terminate Edge processes + foreach ($process in $processes) { + Stop-Process -Id $process -Force + } + foreach ($service in $services) { + Stop-Service -Name $service -Force + } $ErrorActionPreference = 'Continue' @@ -158,9 +163,9 @@ function UninstallAll { if ($removeWebView) { Write-Warning "Uninstalling Edge WebView..." RemoveWebView - Write-Warning "Uninstalling Edge Update..." - DeleteEdgeUpdate } + Write-Warning "Uninstalling Edge Update..." + DeleteEdgeUpdate } function Completed {