From 6c29ff836e566c82ac6749a8c79ce7c8430631bc Mon Sep 17 00:00:00 2001 From: zoicware <118035521+zoicware@users.noreply.github.com> Date: Sun, 8 Jun 2025 15:53:14 -0400 Subject: [PATCH] Fix #9 --- RemoveWindowsAi.ps1 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index 25d64ee..6a9d64e 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -5,7 +5,12 @@ If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]: function Run-Trusted([String]$command) { - Stop-Service -Name TrustedInstaller -Force -ErrorAction SilentlyContinue + try { + Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop + } + catch { + taskkill /im trustedinstaller.exe /f >$null + } #get bin path to revert later $service = Get-WmiObject -Class Win32_Service -Filter "Name='TrustedInstaller'" $DefaultBinPath = $service.PathName @@ -18,8 +23,13 @@ function Run-Trusted([String]$command) { sc.exe start TrustedInstaller | Out-Null #set bin back to default sc.exe config TrustedInstaller binpath= "`"$DefaultBinPath`"" | Out-Null - Stop-Service -Name TrustedInstaller -Force -ErrorAction SilentlyContinue - + try { + Stop-Service -Name TrustedInstaller -Force -ErrorAction Stop -WarningAction Stop + } + catch { + taskkill /im trustedinstaller.exe /f >$null + } + } function Write-Status {