mirror of
https://github.com/zoicware/RemoveWindowsAI.git
synced 2025-12-17 07:06:29 +01:00
additional error handling when removing cbs packages
This commit is contained in:
@@ -1131,23 +1131,38 @@ function Remove-AI-CBS-Packages {
|
|||||||
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
|
$regPath = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages'
|
||||||
$ProgressPreference = 'SilentlyContinue'
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
Get-ChildItem $regPath | ForEach-Object {
|
Get-ChildItem $regPath | ForEach-Object {
|
||||||
$value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction SilentlyContinue } catch {}
|
$value = try { Get-ItemPropertyValue "registry::$($_.Name)" -Name Visibility -ErrorAction Stop } catch { $null }
|
||||||
if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') {
|
|
||||||
Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force
|
if ($value -ne $null) {
|
||||||
New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force
|
if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') {
|
||||||
Remove-Item "registry::$($_.Name)\Owners" -Force -ErrorAction SilentlyContinue
|
Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force
|
||||||
Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue
|
New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force
|
||||||
try {
|
Remove-Item "registry::$($_.Name)\Owners" -Force -ErrorAction SilentlyContinue
|
||||||
Remove-WindowsPackage -Online -PackageName $_.PSChildName -NoRestart -ErrorAction Stop *>$null
|
Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue
|
||||||
Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" | Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue
|
try {
|
||||||
}
|
Remove-WindowsPackage -Online -PackageName $_.PSChildName -NoRestart -ErrorAction Stop *>$null
|
||||||
catch {
|
$paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue
|
||||||
#fallback to dism when user is using powershell 7
|
foreach ($path in $paths) {
|
||||||
dism.exe /Online /Remove-Package /PackageName:$($_.PSChildName) /NoRestart /Quiet
|
if ($path) {
|
||||||
Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" | Remove-Item $_.FullName -Force -ErrorAction SilentlyContinue
|
Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
#fallback to dism when user is using powershell 7
|
||||||
|
dism.exe /Online /Remove-Package /PackageName:$($_.PSChildName) /NoRestart /Quiet
|
||||||
|
$paths = Get-ChildItem "$env:windir\servicing\Packages" -Filter "*$($_.PSChildName)*" -ErrorAction SilentlyContinue
|
||||||
|
foreach ($path in $paths) {
|
||||||
|
if ($path) {
|
||||||
|
Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2229,6 +2244,7 @@ else {
|
|||||||
'WorkloadsSessionHost.exe'
|
'WorkloadsSessionHost.exe'
|
||||||
'WebViewHost.exe'
|
'WebViewHost.exe'
|
||||||
'aimgr.exe'
|
'aimgr.exe'
|
||||||
|
'AppActions.exe'
|
||||||
)
|
)
|
||||||
foreach ($procName in $aiProcesses) {
|
foreach ($procName in $aiProcesses) {
|
||||||
taskkill /im $procName /f *>$null
|
taskkill /im $procName /f *>$null
|
||||||
|
|||||||
Reference in New Issue
Block a user