|
|
发表于 2026-11-4 09:53:35
|
显示全部楼层
本帖最后由 xlqd09311 于 2026-11-4 09:57 编辑

我也做了一个,对自己有用,但不一定适合大众。

<#
.SYNOPSIS
系统清理 + 功能禁用与隐藏 + 关闭通知 + 隐藏辅助功能 + 视觉效果自定义
.DESCRIPTION
1) 分析组件存储
2) 深度清理 ResetBase(不可逆)
3) 验证 + 关闭休眠/保留存储
4) 清理还原点(vssadmin) + 临时文件
5) 隐藏控制面板项
6) 禁用防火墙 + 隐藏安全中心区域
7) 关闭远程功能
8) 彻底关闭通知
9) 隐藏辅助功能页面
10) 视觉效果自定义(尝试:开字体平滑/缩略图/指针阴影,关其余)
.NOTES
视觉效果精确勾选状态无法保证,窗口阴影无可靠独立注册表开关。
必须以管理员身份运行。
#>
$ErrorActionPreference = "Continue"
function Show-Step { param($i,$t,$s) Write-Host "`n$("="*60)" -ForegroundColor Cyan; Write-Host " 步骤 $i/$t $s" -ForegroundColor Cyan; Write-Host ("="*60) -ForegroundColor Cyan }
function Show-Result { param($n,$c,$st) $e=(Get-Date)-$st; if($c-eq 0){Write-Host " [完成] $n 耗时 $($e.ToString('mm\:ss'))" -ForegroundColor Green}else{Write-Host " [失败] $n" -ForegroundColor Red} }
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "错误:请以管理员身份运行。" -ForegroundColor Red; Read-Host "按回车退出"; exit 1
}
$total = 10
$startAll = Get-Date
$freeBefore = (Get-PSDrive C).Free / 1GB
Write-Host "`n系统清理 + 功能禁用 + 隐藏 + 视觉效果 (合并版)" -ForegroundColor Magenta
# 1. WinSxS 分析
Show-Step 1 $total "分析组件存储"
$t=Get-Date; Dism /Online /Cleanup-Image /AnalyzeComponentStore; Show-Result "分析" $LASTEXITCODE $t
# 2. WinSxS 深度清理
Show-Step 2 $total "深度清理 ResetBase(不可逆)"
Write-Host " 提示:耗时较长,请勿中断。" -ForegroundColor DarkYellow
$t=Get-Date; Dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase; Show-Result "ResetBase" $LASTEXITCODE $t
# 3. 验证 + 释放空间
Show-Step 3 $total "验证 + 关闭休眠/保留存储"
$t=Get-Date; Dism /Online /Cleanup-Image /AnalyzeComponentStore | Select-String "实际|Actual"
if (Test-Path C:\hiberfil.sys) { powercfg /h off; Write-Host " 休眠已关闭" -ForegroundColor Green }
Dism /Online /Set-ReservedStorageState /State:Disabled | Out-Null
Show-Result "释放空间" 0 $t
# 4. 清理还原点/临时文件
Show-Step 4 $total "清理旧还原点(vssadmin) + 临时文件"
$t=Get-Date
try {
$vssOut = vssadmin list shadows 2>&1 | Out-String
$ids = [regex]::Matches($vssOut, '\{[0-9a-fA-F\-]{36}\}') | ForEach-Object { $_.Value } | Select-Object -Unique
if ($ids.Count -gt 1) {
$ids | Select-Object -SkipLast 1 | ForEach-Object { vssadmin delete shadows /shadow=$_ /quiet 2>&1 | Out-Null }
Write-Host " 已删除旧还原点。" -ForegroundColor Green
} else { Write-Host " 无需清理还原点。" -ForegroundColor DarkGray }
} catch { Write-Host " 还原点清理跳过。" -ForegroundColor Yellow }
Get-ChildItem "$env:SystemRoot\Temp","$env:TEMP","$env:LOCALAPPDATA\Temp" -Recurse -Force -EA SilentlyContinue | Remove-Item -Recurse -Force -EA SilentlyContinue
Show-Result "清理垃圾" 0 $t
# 5. 隐藏控制面板项
Show-Step 5 $total "隐藏指定控制面板项"
$t=Get-Date
$cpls = @("Microsoft.iSCSIInitiator","Microsoft.CredentialManager","Microsoft.ColorManagement","Microsoft.AutoPlay","Microsoft.SpeechRecognition","Microsoft.TextToSpeech","Microsoft.WindowsFirewall")
$rp = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
if (-not (Test-Path $rp)) { New-Item $rp -Force | Out-Null }
Set-ItemProperty $rp "DisallowCpl" 1 -Type DWord -Force
$sub = Join-Path $rp "DisallowCpl"; if (-not (Test-Path $sub)) { New-Item $sub -Force | Out-Null }
$i=1; foreach ($c in $cpls) { New-ItemProperty -Path $sub -Name "$i" -Value $c -PropertyType String -Force | Out-Null; $i++ }
Show-Result "隐藏控制面板" 0 $t
# 6. 禁用防火墙 + 隐藏区域
Show-Step 6 $total "禁用防火墙 + 隐藏安全中心区域"
$t=Get-Date
netsh advfirewall set allprofiles state off | Out-Null
Get-Service MpsSvc | Stop-Service -Force -EA SilentlyContinue; Set-Service MpsSvc -StartupType Disabled -EA SilentlyContinue
$fw = "HKLM:\SOFTWARE\Microsoft\Windows Defender Security Center\Firewall and network protection"
if (-not (Test-Path $fw)) { New-Item $fw -Force | Out-Null }; Set-ItemProperty $fw "UILockdown" 1 -Type DWord -Force
Show-Result "防火墙" 0 $t
# 7. 禁用远程功能
Show-Step 7 $total "禁用远程协助/远程桌面"
$t=Get-Date
$ra = "HKLM:\SYSTEM\CurrentControlSet\Control\Remote Assistance"; if (-not (Test-Path $ra)) { New-Item $ra -Force | Out-Null }
Set-ItemProperty $ra "fAllowToGetHelp" 0 -Type DWord -Force
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" "fDenyTSConnections" 1 -Type DWord -Force
Show-Result "远程功能" 0 $t
# 8. 彻底关闭通知
Show-Step 8 $total "彻底关闭通知"
$t=Get-Date
$policy = "HKCU:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications"
if (Test-Path $policy) { Remove-ItemProperty $policy "NoToastApplicationNotification" -Force -EA SilentlyContinue }
$push = "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications"
if (-not (Test-Path $push)) { New-Item $push -Force | Out-Null }
Set-ItemProperty $push "ToastEnabled" 0 -Type DWord -Force
$vis = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"; $vn = "SettingsPageVisibility"
if (-not (Test-Path $vis)) { New-Item $vis -Force | Out-Null }
$cur = (Get-ItemProperty $vis $vn -EA SilentlyContinue).$vn
if ($cur -and $cur -match "^hide:(.+)$") { $items = $matches[1] -split ";" | ? {$_}; if ($items -notcontains "notifications") { Set-ItemProperty $vis $vn ("hide:" + (($items + "notifications") -join ";")) -Type String -Force } }
else { Set-ItemProperty $vis $vn "hide:notifications" -Type String -Force }
Show-Result "关闭通知" 0 $t
# 9. 隐藏辅助功能页面
Show-Step 9 $total "隐藏辅助功能全部页面"
$t=Get-Date
$ease = @("easeofaccess-narrator","easeofaccess-closedcaptioning","easeofaccess-audio","easeofaccess-display","easeofaccess-highcontrast","easeofaccess-keyboard","easeofaccess-mouse","easeofaccess-colorfilter")
$vis9 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"; $vn9 = "SettingsPageVisibility"
if (-not (Test-Path $vis9)) { New-Item $vis9 -Force | Out-Null }
$cur9 = (Get-ItemProperty $vis9 $vn9 -EA SilentlyContinue).$vn9
if ($cur9 -and $cur9 -match "^hide:(.+)$") { $items9 = $matches[1] -split ";" | ? {$_}; $new9 = $ease | ? {$items9 -notcontains $_}; if ($new9.Count -gt 0) { Set-ItemProperty $vis9 $vn9 ("hide:" + (($items9 + $new9) -join ";")) -Type String -Force } }
else { Set-ItemProperty $vis9 $vn9 ("hide:" + ($ease -join ";")) -Type String -Force }
Show-Result "隐藏辅助功能" 0 $t
# 10. 视觉效果自定义(折中方案)
Show-Step 10 $total "视觉效果自定义(折中,无法保证精确勾选)"
Write-Host " 说明:尝试开启字体平滑/缩略图/指针阴影,关闭其余。" -ForegroundColor DarkYellow
Write-Host " 警告:窗口阴影无可靠独立开关,界面勾选状态可能不符预期。" -ForegroundColor Red
$t=Get-Date
# 设为自定义
$vf = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects"
if (-not (Test-Path $vf)) { New-Item $vf -Force | Out-Null }
Set-ItemProperty $vf "VisualFXSetting" 3 -Type DWord -Force
# 开启字体平滑
Set-ItemProperty "HKCU:\Control Panel\Desktop" "FontSmoothing" "2" -Type String -Force
# 显示缩略图
Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" "IconsOnly" 0 -Type DWord -Force
# UserPreferencesMask:使用“最佳性能”基准值(关闭大部分特效)
# 尝试开启指针阴影(Bit 13),但窗口阴影无法保证
$mask = [byte[]](0x90, 0x12, 0x03, 0x80, 0x10, 0x00, 0x00, 0x00)
# 尝试开启 Bit 13(第二字节 0x12 -> 0x32)
$mask[1] = 0x32
Set-ItemProperty "HKCU:\Control Panel\Desktop" "UserPreferencesMask" $mask -Type Binary -Force
Write-Host " 已写入自定义模式、字体平滑、缩略图、指针阴影尝试值。" -ForegroundColor Green
Write-Host " 结果需注销重登后查看,界面勾选可能不完全匹配。" -ForegroundColor DarkYellow
Show-Result "视觉效果设置" 0 $t
# 汇总
$endAll = Get-Date
$freeAfter = (Get-PSDrive C).Free / 1GB
Write-Host "`n$("="*60)" -ForegroundColor Green
Write-Host " 全部完成" -ForegroundColor Green
Write-Host " C 盘释放: $([math]::Round($freeAfter-$freeBefore,2)) GB" -ForegroundColor Green
Write-Host " 总耗时: $(($endAll-$startAll).ToString('hh\:mm\:ss'))" -ForegroundColor Green
Write-Host " 视觉效果精确勾选无法保证,窗口阴影需手动在性能选项中确认。" -ForegroundColor DarkYellow
Write-Host ("="*60) -ForegroundColor Green
Read-Host "`n按回车退出"

有需要的朋友复制以上代码,别存为powershell文件即可
|
|