From cb4c16a08057140895233602ca9ae910fbd16d22 Mon Sep 17 00:00:00 2001 From: zoicware <118035521+zoicware@users.noreply.github.com> Date: Tue, 9 Dec 2025 16:47:35 -0500 Subject: [PATCH] add error handling when svcs are already removed --- RemoveWindowsAi.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index 84b51b7..3a20dbd 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -322,7 +322,13 @@ function Disable-Registry-Keys { Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableGenerativeErase' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null Reg.exe add 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Paint' /v 'DisableRemoveBackground' /t REG_DWORD /d @('1', '0')[$revert] /f *>$null Reg.exe add 'HKLM\SYSTEM\CurrentControlSet\Services\WSAIFabricSvc' /v 'Start' /t REG_DWORD /d @('4', '2')[$revert] /f *>$null - Stop-Service -Name WSAIFabricSvc -Force -ErrorAction SilentlyContinue + try { + Stop-Service -Name WSAIFabricSvc -Force -ErrorAction Stop + } + catch { + #ignore error when svc is already removed + } + $backupPath = "$env:USERPROFILE\RemoveWindowsAI\Backup" $backupFileWSAI = 'WSAIFabricSvc.reg' $backupFileAAR = 'AARSVC.reg' @@ -348,7 +354,7 @@ function Disable-Registry-Keys { Reg.exe export 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WSAIFabricSvc' "$backupPath\$backupFileWSAI" | Out-Null } } - Write-Status -msg 'Removing up WSAIFabricSvc...' + Write-Status -msg 'Removing WSAIFabricSvc...' #delete the service sc.exe delete WSAIFabricSvc *>$null } @@ -370,7 +376,13 @@ function Disable-Registry-Keys { } Write-Status -msg 'Removing Agent Activation Runtime Service...' #delete the service - Stop-Service -Name $aarSVCName -Force -ErrorAction SilentlyContinue + try { + Stop-Service -Name $aarSVCName -Force -ErrorAction Stop + } + catch { + #ignore error when svc is already removed + } + sc.exe delete AarSvc *>$null } }