新装系统,自带bing,右键,任务栏到处都是,写个一键清除脚本的功能
双击运行后,选择“是”授予管理员权限。脚本会卸载 Microsoft Store 版 Bing 壁纸、清理相关启动项,并删除各账户桌面和下载文件夹中名称匹配的安装包。运行结果会显示在窗口中;如果右键菜单或任务栏图标仍显示,请重启电脑。
将以下代码保存成 .bat 文件
@echo off
setlocal
chcp 65001 >nul
set "BING_CLEANUP_SCRIPT=%~f0"
net session >nul 2>&1
if not "%errorlevel%"=="0" (
echo Requesting administrator permission...
powershell.exe -NoProfile -Command "Start-Process -FilePath $env:BING_CLEANUP_SCRIPT -Verb RunAs"
exit /b
)
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$s = Get-Content -LiteralPath $env:BING_CLEANUP_SCRIPT -Raw -Encoding UTF8; $parts = $s -split '(?m)^:__POWERSHELL__\s*\r?$', 2; if ($parts.Count -ne 2) { exit 2 }; & ([scriptblock]::Create($parts[1]))"
echo.
pause
exit /b
:__POWERSHELL__
$ErrorActionPreference = 'Continue'
$problems = New-Object System.Collections.Generic.List[string]
Write-Host '正在关闭 Bing 壁纸进程...'
Get-Process BingWallpaper, UnInstDaemon -ErrorAction SilentlyContinue | Where-Object { $_.ProcessName -eq 'BingWallpaper' -or $_.Path -match '\\bwp[^\\]*\\UnInstDaemon\.exe$' } | Stop-Process -Force -ErrorAction SilentlyContinue
Write-Host '正在卸载 Bing 壁纸应用(所有账户)...'
try {
$packages = @(Get-AppxPackage -AllUsers -Name Microsoft.BingWallpaper -ErrorAction Stop)
foreach ($package in $packages) {
try { Remove-AppxPackage -Package $package.PackageFullName -AllUsers -ErrorAction Stop; Write-Host "已卸载:$($package.PackageFullName)" }
catch { $problems.Add("应用卸载失败:$($_.Exception.Message)") }
}
if ($packages.Count -eq 0) { Write-Host '没有发现已安装的 Bing 壁纸应用。' }
} catch { $problems.Add("无法检查所有账户的应用:$($_.Exception.Message)") }
try {
$provisioned = @(Get-AppxProvisionedPackage -Online -ErrorAction Stop | Where-Object DisplayName -eq 'Microsoft.BingWallpaper')
foreach ($package in $provisioned) {
try { Remove-AppxProvisionedPackage -Online -PackageName $package.PackageName -ErrorAction Stop | Out-Null; Write-Host '已移除系统预配的 Bing 壁纸。' }
catch { $problems.Add("移除预配应用失败:$($_.Exception.Message)") }
}
} catch { $problems.Add("无法检查系统预配应用:$($_.Exception.Message)") }
Write-Host '正在清理启动项和安装包...'
$hives = @('HKCU:') + @(Get-ChildItem Registry::HKEY_USERS -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -match '^S-1-5-21-(\d+-){3}\d+$' } | ForEach-Object { 'Registry::' + $_.Name })
foreach ($hive in $hives) {
foreach ($subkey in @('Software\Microsoft\Windows\CurrentVersion\Run','Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run')) {
$key = "$hive\$subkey"
if (Get-ItemProperty -LiteralPath $key -Name BingWallpaperDaemon -ErrorAction SilentlyContinue) {
try { Remove-ItemProperty -LiteralPath $key -Name BingWallpaperDaemon -ErrorAction Stop; Write-Host "已清理启动项:$key" }
catch { $problems.Add("启动项清理失败:$key") }
}
}
}
$profileRoot = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
$profiles = @(Get-ChildItem $profileRoot -ErrorAction SilentlyContinue | ForEach-Object { (Get-ItemProperty $_.PSPath -ErrorAction SilentlyContinue).ProfileImagePath } | Where-Object { $_ } | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) } | Select-Object -Unique)
foreach ($profile in $profiles) {
foreach ($folder in @('Downloads','Desktop')) {
$dir = Join-Path $profile $folder
if (-not (Test-Path -LiteralPath $dir -PathType Container)) { continue }
Get-ChildItem -LiteralPath $dir -File -ErrorAction SilentlyContinue | Where-Object { $_.Name -match '^(BingWallpaper|Bing_Wallpaper|Bing-Wallpaper)(Installer|Setup)?[^\\]*\.(exe|msi|msix|msixbundle|appx|appxbundle)$' } | ForEach-Object {
try { Remove-Item -LiteralPath $_.FullName -Force -ErrorAction Stop; Write-Host "已删除安装包:$($_.FullName)" }
catch { $problems.Add("无法删除安装包:$($_.FullName)") }
}
}
$temp = Join-Path $profile 'AppData\Local\Temp'
if (Test-Path -LiteralPath $temp -PathType Container) {
Get-ChildItem -LiteralPath $temp -Directory -Filter 'bwp*' -ErrorAction SilentlyContinue | Where-Object { Test-Path -LiteralPath (Join-Path $_.FullName 'UnInstDaemon.exe') -PathType Leaf } | ForEach-Object {
try { Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction Stop; Write-Host "已删除卸载临时文件:$($_.FullName)" }
catch { $problems.Add("无法删除临时文件:$($_.FullName)") }
}
}
}
Write-Host ''
if ($problems.Count) { Write-Host '以下项目未能完成:' -ForegroundColor Yellow; $problems | ForEach-Object { Write-Host "- $_" }; exit 1 }
try {
$remaining = @(Get-AppxPackage -AllUsers -Name Microsoft.BingWallpaper -ErrorAction Stop)
if ($remaining.Count) { Write-Host '仍有 Bing 壁纸应用未卸载,请检查 Windows 设置中的应用列表。' -ForegroundColor Yellow; exit 1 }
} catch { Write-Host '无法验证其他账户的卸载状态。' -ForegroundColor Yellow; exit 1 }
Write-Host '清理完成。如果右键菜单或任务栏图标仍显示,请重启电脑。' -ForegroundColor Green