|
|
本帖最后由 lifeway 于 2026-1-24 18:43 编辑
那是肯定。要不毫无意义。你精简appx、apps还是组件,总是不完全了。还想要开关功能?,重新从winsxs恢复appx?我还在注册表禁止了精简的包呢。
这是从remove windowsAI学习的。
- function Remove-AI-Files {
- param(
- [Parameter(Mandatory=$true)]
- [string]$ScratchDir
- )
-
- Write-Host "`n=== 开始移除 AI 文件 ===" -ForegroundColor Cyan
-
- $aipackages = @(
- # 'MicrosoftWindows.Client.Photon'
- 'MicrosoftWindows.Client.AIX'
- 'MicrosoftWindows.Client.CoPilot'
- 'Microsoft.Windows.Ai.Copilot.Provider'
- 'Microsoft.Copilot'
- 'Microsoft.MicrosoftOfficeHub'
- 'MicrosoftWindows.Client.CoreAI'
- 'Microsoft.Edge.GameAssist'
- 'Microsoft.Office.ActionsServer'
- 'aimgr'
- 'Microsoft.WritingAssistant'
- #ai component packages installed on copilot+ pcs
- 'WindowsWorkload'
- 'Voiess'
- 'Speion'
- 'Livtop'
- 'InpApp'
- 'Filons'
- )
- Write-Host 'Removing Appx Package Files...'
- Write-Host 'This could take a while on some systems, please be patient!'
-
- #-----------------------------------------------------------------------remove files
- $appsPath = "$ScratchDir\Windows\SystemApps"
- if (!(Test-Path $appsPath)) {
- $appsPath = "$ScratchDir\Windows\SystemApps"
- }
- $appsPath2 = "$ScratchDir\Program Files\WindowsApps"
-
- $appsPath3 = "$ScratchDir\ProgramData\Microsoft\Windows\AppRepository"
-
- $appsPath4 = "$ScratchDir\Windows\servicing\Packages"
- if (!(Test-Path $appsPath4)) {
- $appsPath4 = "$ScratchDir\Windows\servicing\Packages"
- }
-
- $appsPath5 = "$ScratchDir\Windows\System32\CatRoot"
- if (!(Test-Path $appsPath5)) {
- $appsPath5 = "$ScratchDir\Windows\System32\CatRoot"
- }
- $appsPath6 = "$ScratchDir\Windows\SystemApps\SxS"
- if (!(Test-Path $appsPath6)) {
- $appsPath6 = "$ScratchDir\Windows\SystemApps\SxS"
- }
-
- $pathsSystemApps = (Get-ChildItem -Path $appsPath -Directory -Force -ErrorAction SilentlyContinue).FullName
- $pathsWindowsApps = (Get-ChildItem -Path $appsPath2 -Directory -Force -ErrorAction SilentlyContinue).FullName
- $pathsAppRepo = (Get-ChildItem -Path $appsPath3 -Directory -Force -Recurse -ErrorAction SilentlyContinue).FullName
- $pathsServicing = (Get-ChildItem -Path $appsPath4 -Directory -Force -Recurse -ErrorAction SilentlyContinue).FullName
- $pathsCatRoot = (Get-ChildItem -Path $appsPath5 -Directory -Force -Recurse -ErrorAction SilentlyContinue).FullName
- $pathsSXS = (Get-ChildItem -Path $appsPath6 -Directory -Force -ErrorAction SilentlyContinue).FullName
- $packagesPath = @()
- #get full path
- foreach ($package in $aipackages) {
- foreach ($path in $pathsSystemApps) {
- if ($path -like "*$package*") {
- $packagesPath += $path
- }
- }
- foreach ($path in $pathsWindowsApps) {
- if ($path -like "*$package*") {
- $packagesPath += $path
- }
- }
- foreach ($path in $pathsAppRepo) {
- if ($path -like "*$package*") {
- $packagesPath += $path
- }
- }
- foreach ($path in $pathsSXS) {
- if ($path -like "*$package*") {
- $packagesPath += $path
- }
- }
- }
- #get additional files
- foreach ($path in $pathsServicing) {
- if ($path -like '*UserExperience-AIX*' -or $path -like '*Copilot*' -or $path -like '*UserExperience-Recall*' -or $path -like '*CoreAI*') {
- $packagesPath += $path
- }
- }
- foreach ($path in $pathsCatRoot) {
- if ($path -like '*UserExperience-AIX*' -or $path -like '*Copilot*' -or $path -like '*UserExperience-Recall*' -or $path -like '*CoreAI*') {
- $packagesPath += $path
- }
- }
- #add app actions mcp host
- $paths = @(
- "$ScratchDir\Users\Default\AppData\Local\Microsoft\WindowsApps\ActionsMcpHost.exe"
- "$ScratchDir\Windows\System32\config\systemprofile\AppData\Local\Microsoft\WindowsApps\ActionsMcpHost.exe"
- "$ScratchDir\Windows\System32\config\systemprofile\AppData\Local\Microsoft\WindowsApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionsMcpHost.exe"
- "$ScratchDir\Users\Default\AppData\Local\Microsoft\WindowsApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionsMcpHost.exe"
- )
- foreach ($path in $paths) {
- if (Test-Path $path) {
- $packagesPath += $path
- }
- }
- foreach ($packageName in $aipackages) {
- $path = Get-ChildItem "$ScratchDir\Users\Default\AppData\Local\Packages" -Filter "*$packageName*" -ErrorAction SilentlyContinue
- if ($path) {
- $packagesPath += $path.FullName
- }
- }
- foreach ($Path in $packagesPath) {
- Remove-item $Path -force -recurse -ErrorAction SilentlyContinue
- Start-Sleep 1
- }
- #remove machine learning dlls
- $paths = @(
- "$ScratchDir\Windows\System32\Windows.AI.MachineLearning.dll"
- "$ScratchDir\Windows\SysWOW64\Windows.AI.MachineLearning.dll"
- "$ScratchDir\Windows\System32\Windows.AI.MachineLearning.Preview.dll"
- "$ScratchDir\Windows\SysWOW64\Windows.AI.MachineLearning.Preview.dll"
- "$ScratchDir\Windows\System32\SettingsHandlers_Copilot.dll"
- "$ScratchDir\Windows\System32\SettingsHandlers_A9.dll"
- )
- foreach ($path in $paths) {
- if (Test-Path $path) {
- Remove-Item -Path $path -Force -ErrorAction SilentlyContinue
- }
- }
- Write-Host 'Removing Hidden Copilot Installers...'
- #remove package installers in edge dir
- #installs Microsoft.Windows.Ai.Copilot.Provider
- $dir = "$ScratchDir\Program Files (x86)\Microsoft"
- $folders = @(
- 'Edge',
- 'EdgeCore',
- 'EdgeWebView'
- )
- foreach ($folder in $folders) {
- if ($folder -eq 'EdgeCore') {
- $fullPath = (Get-ChildItem -Path "$dir\$folder\*.*.*.*\copilot_provider_msix" -ErrorAction SilentlyContinue).FullName
- }
- else {
- $fullPath = (Get-ChildItem -Path "$dir\$folder\Application\*.*.*.*\copilot_provider_msix" -ErrorAction SilentlyContinue).FullName
- }
- if ($fullPath -ne $null) { Remove-Item -Path $fullPath -Recurse -Force -ErrorAction SilentlyContinue }
- }
- #remove copilot update in edge update dir
- $dir = "$ScratchDir\Program Files (x86)\Microsoft\EdgeUpdate"
- if (Test-Path $dir) {
- $paths = Get-ChildItem $dir -Recurse -Filter '*CopilotUpdate.exe*'
- foreach ($path in $paths) {
- if (Test-Path $path.FullName) {
- Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
- }
- }
- }
- $dir = "$ScratchDir\Program Files (x86)\Microsoft"
- if (Test-Path $dir) {
- $paths = Get-ChildItem $dir -Recurse -Filter '*Copilot_setup*'
- foreach ($path in $paths) {
- if (Test-Path $path.FullName) {
- Remove-Item $path.FullName -Force -ErrorAction SilentlyContinue
- }
- }
- }
- # 加载注册表删除相关键值
- Write-Host "`n加载注册表进行清理..." -ForegroundColor Yellow
- $softwareMountKey = "TempFileCleanup_$(Get-Random -Minimum 1000 -Maximum 9999)"
- $softwareHivePath = Join-Path $ScratchDir "Windows\System32\config\SOFTWARE"
-
- Write-Host "加载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- if (Test-Path $softwareHivePath) {
- $null = reg.exe load "HKLM\$softwareMountKey" "$softwareHivePath" 2>$null
- if ($LASTEXITCODE -eq 0) {
- Write-Host " [成功]" -ForegroundColor Green
-
- # 删除 EdgeUpdate 注册表项
- Write-Host "删除 EdgeUpdate 注册表项..." -NoNewline -ForegroundColor DarkYellow
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\EdgeUpdate" /v "CopilotUpdatePath" /f 2>$null
- $null = reg.exe delete "HKLM\$softwareMountKey\WOW6432Node\Microsoft\EdgeUpdate" /v "CopilotUpdatePath" /f 2>$null
- Write-Host " [完成]" -ForegroundColor Green
-
- #remove additional installers
- $inboxapps = "$ScratchDir\Windows\InboxApps"
- $installers = Get-ChildItem -Path $inboxapps -Filter '*Copilot*' -ErrorAction SilentlyContinue
- foreach ($installer in $installers) {
- Remove-Item -Path $installer.FullName -Force -ErrorAction SilentlyContinue
- }
-
- Write-Host "卸载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- $null = reg.exe unload "HKLM\$softwareMountKey" 2>$null
- Write-Host " [完成]" -ForegroundColor Green
- } else {
- Write-Host " [失败]" -ForegroundColor Red
- }
- } else {
- Write-Host " [文件不存在]" -ForegroundColor Red
- }
- #remove ai from outlook/office
- $aiPaths = @(
- "$ScratchDir\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\AI",
- "$ScratchDir\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX86\Microsoft Shared\Office16\AI",
- "$ScratchDir\Program Files\Microsoft Office\root\Office16\AI",
- "$ScratchDir\Program Files\Microsoft Office\root\vfs\ProgramFilesCommonX64\Microsoft Shared\Office16\ActionsServer",
- "$ScratchDir\Program Files\Microsoft Office\root\Integration\Addons\aimgr.msix",
- "$ScratchDir\Program Files\Microsoft Office\root\Integration\Addons\WritingAssistant.msix",
- "$ScratchDir\Program Files\Microsoft Office\root\Integration\Addons\ActionsServer.msix"
- )
- foreach ($path in $aiPaths) {
- if (Test-Path $path -ErrorAction SilentlyContinue) {
- Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue
- }
- }
- #remove any screenshots from recall
- Write-Host 'Removing Any Screenshots By Recall...'
- Remove-Item -Path "$ScratchDir\Users\Default\AppData\Local\CoreAIPlatform*" -Force -Recurse -ErrorAction SilentlyContinue
- # 加载注册表删除 AI URI 处理器
- Write-Host "`n加载注册表删除 AI URI 处理器..." -ForegroundColor Yellow
- $softwareMountKey = "TempURICleanup_$(Get-Random -Minimum 1000 -Maximum 9999)"
- $systemMountKey = "TempSystemURICleanup_$(Get-Random -Minimum 1000 -Maximum 9999)"
-
- $softwareHivePath = Join-Path $ScratchDir "Windows\System32\config\SOFTWARE"
- $systemHivePath = Join-Path $ScratchDir "Windows\System32\config\SYSTEM"
-
- Write-Host "加载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- if (Test-Path $softwareHivePath) {
- $null = reg.exe load "HKLM\$softwareMountKey" "$softwareHivePath" 2>$null
- if ($LASTEXITCODE -eq 0) {
- Write-Host " [成功]" -ForegroundColor Green
-
- #remove ai uri handlers
- Write-Host 'Removing AI URI Handlers...'
- $uris = @(
- "HKLM\$softwareMountKey\Classes\ms-office-ai"
- "HKLM\$softwareMountKey\Classes\ms-copilot"
- "HKLM\$softwareMountKey\Classes\ms-clicktodo"
- )
- foreach ($uri in $uris) {
- $null = reg.exe delete $uri /f 2>$null
- }
- #prefire copilot nudges package by deleting the registry keys
- Write-Host 'Removing Copilot Nudges Registry Keys...'
-
- # 删除 Shell Update 注册表项
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\MicrosoftWindows.Client.CoreAI_cw5n1h2txyewy" /f 2>$null
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components" /v "AIX" /f 2>$null
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components" /v "CopilotNudges" /f 2>$null
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\Shell\Update\Packages\Components" /v "AIContext" /f 2>$null
- # 删除 App Paths
- $null = reg.exe delete "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\App Paths\ActionsMcpHost.exe" /f 2>$null
-
- Write-Host "卸载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- $null = reg.exe unload "HKLM\$softwareMountKey" 2>$null
- Write-Host " [完成]" -ForegroundColor Green
- } else {
- Write-Host " [失败]" -ForegroundColor Red
- }
- } else {
- Write-Host " [文件不存在]" -ForegroundColor Red
- }
-
- Write-Host "加载SYSTEM配置单元..." -NoNewline -ForegroundColor DarkYellow
- if (Test-Path $systemHivePath) {
- $null = reg.exe load "HKLM\$systemMountKey" "$systemHivePath" 2>$null
- if ($LASTEXITCODE -eq 0) {
- Write-Host " [成功]" -ForegroundColor Green
- Write-Host "卸载SYSTEM配置单元..." -NoNewline -ForegroundColor DarkYellow
- $null = reg.exe unload "HKLM\$systemMountKey" 2>$null
- Write-Host " [完成]" -ForegroundColor Green
- } else {
- Write-Host " [失败]" -ForegroundColor Red
- }
- } else {
- Write-Host " [文件不存在]" -ForegroundColor Red
- }
- #remove app actions files
- $paths = @(
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ActionUI"
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssist"
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\AppActions.exe"
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\AppActions.dll"
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssistExe.exe"
- "$ScratchDir\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\VisualAssistExe.dll"
- )
- Write-Host 'Removing App Actions Files...'
- foreach ($path in $paths) {
- if (Test-Path $path) {
- Remove-Item $path -Force -Recurse -ErrorAction SilentlyContinue
- }
- }
-
- Write-Host 'Removing AI From Component Store (WinSxS)...'
- Write-Host 'This could take a while on some systems, please be patient!'
- #additional dirs and reg keys
- $aiKeyWords = @(
- 'AIX',
- 'Copilot',
- 'Recall',
- 'CoreAI',
- 'aimgr'
- )
-
- # 加载注册表进行清理
- Write-Host "`n加载注册表进行最终清理..." -ForegroundColor Yellow
- $softwareMountKey = "TempFinalCleanup_$(Get-Random -Minimum 1000 -Maximum 9999)"
- $softwareHivePath = Join-Path $ScratchDir "Windows\System32\config\SOFTWARE"
-
- Write-Host "加载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- if (Test-Path $softwareHivePath) {
- $null = reg.exe load "HKLM\$softwareMountKey" "$softwareHivePath" 2>$null
- if ($LASTEXITCODE -eq 0) {
- Write-Host " [成功]" -ForegroundColor Green
-
- $regLocations = @(
- "HKLM\$softwareMountKey\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage",
- "HKLM\$softwareMountKey\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages",
- "HKLM\$softwareMountKey\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData",
- "HKLM\$softwareMountKey\Classes\PackagedCom\Package",
- "HKLM\$softwareMountKey\Microsoft\Windows\CurrentVersion\SideBySide\Winners"
- )
- foreach ($keyword in $aiKeyWords) {
- foreach ($location in $regLocations) {
- $command = "reg query `"$location`" /s /k 2>nul | findstr /i `"$keyword`""
- $items = cmd /c $command
- if ($items) {
- foreach ($item in $items) {
- $cleanItem = $item.Trim()
- if ($cleanItem -and $cleanItem -match "^HKEY_") {
- $null = reg.exe delete "$cleanItem" /f 2>$null
- }
- }
- }
- }
- }
-
- Write-Host "卸载SOFTWARE配置单元..." -NoNewline -ForegroundColor DarkYellow
- $null = reg.exe unload "HKLM\$softwareMountKey" 2>$null
- Write-Host " [完成]" -ForegroundColor Green
- } else {
- Write-Host " [失败]" -ForegroundColor Red
- }
- } else {
- Write-Host " [文件不存在]" -ForegroundColor Red
- }
- $dirs = @(
- "$ScratchDir\Windows\WinSxS",
- "$ScratchDir\Windows\System32\CatRoot"
- )
- foreach ($dir in $dirs) {
- Get-ChildItem $dir -Recurse -ErrorAction SilentlyContinue | Where-Object {
- $_.FullName -like "*$($aiKeyWords[0])*" -or
- $_.FullName -like "*$($aiKeyWords[1])*" -or
- $_.FullName -like "*$($aiKeyWords[2])*" -or
- $_.FullName -like "*$($aiKeyWords[3])*" -or
- $_.FullName -like "*$($aiKeyWords[4])*" -and
- $(Test-Path $_.FullName -PathType Container) -eq $true
- } | ForEach-Object {
- Remove-Item $_.FullName -Force -Recurse -ErrorAction SilentlyContinue
- }
- }
-
- Write-Host 'AI 文件移除完成!'
- }
复制代码
|
|