閑著無聊,近來電腦有些卡頓,記錄一下相關命令。最好的命令還是格式化╮(╯▽╰)╭
1. 磁盤清理相關命令
cleanmgr - 磁盤清理工具
cleanmgr
- 啟動磁盤清理工具,可清理臨時文件、回收站等內容
diskpart - 磁盤分區工具
diskpart
- 用于磁盤管理,可以清理、格式化、分區磁盤
defrag - 磁盤碎片整理
defrag C: /U /V
- 對C盤進行碎片整理,顯示進度和詳細信息
2. 系統文件優化命令
sfc - 系統文件檢查器
sfc /scannow
- 掃描并修復損壞的系統文件
DISM - 部署映像服務和管理工具
DISM /Online /Cleanup-Image /RestoreHealth
- 修復Windows系統映像
清理Windows更新文件
DISM /Online /Cleanup-Image /StartComponentCleanup
- 清理過期的Windows更新文件
3. 網絡優化命令
刷新DNS緩存
ipconfig /flushdns
- 清除DNS解析緩存
重置網絡設置
netsh winsock reset
- 重置Winsock目錄
重置TCP/IP協議棧
netsh int ip reset
4. 服務和啟動項優化
禁用不必要的服務
sc config DiagTrack start= disabled
sc config dmwappushservice start= disabled
- 禁用遙測相關服務
關閉快速啟動
powercfg /h off
- 禁用休眠和快速啟動功能以節省空間
5. 注冊表優化命令
關閉自動播放
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers" /v DisableAutoplay /t REG_DWORD /d 1 /f
禁用Windows錯誤報告
reg add "HKLM\SOFTWARE\Microsoft\Windows\Windows Error Reporting" /v Disabled /t REG_DWORD /d 1 /f
6. PowerShell優化腳本
清理臨時文件
Get-ChildItem "C:\Windows\Temp\*" | Remove-Item -Recurse -Force
Get-ChildItem "$env:TEMP\*" | Remove-Item -Recurse -Force
清理Windows更新緩存
Get-ChildItem "C:\Windows\SoftwareDistribution\Download\*" | Remove-Item -Recurse -Force
清理用戶緩存
Get-ChildItem "$env:LOCALAPPDATA\Temp\*" | Remove-Item -Recurse -Force
7. 任務計劃程序優化
禁用不必要的計劃任務
schtasks /change /tn "\Microsoft\Windows\Application Experience\ProgramDataUpdater" /disable
schtasks /change /tn "\Microsoft\Windows\Application Experience\StartupAppTask" /disable
8. 組策略優化(適用于專業版及以上)
關閉客戶體驗改善計劃
reg add "HKLM\SOFTWARE\Policies\Microsoft\SQMClient\Windows" /v "CEIPEnable" /t REG_DWORD /d 0 /f
禁用廣告ID
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo" /v Enabled /t REG_DWORD /d 0 /f
9. 存儲感知優化
啟用存儲感知
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\StorageSense\Parameters\StoragePolicy" /v 01 /t REG_DWORD /d 1 /f
10. 內存優化命令
清理工作集(釋放內存)
EmptyWorkingSets
關閉內存壓縮(需要管理員權限)
Disable-MMAgent -mc
使用建議
- 以管理員身份運行:大部分優化命令需要管理員權限
- 備份重要數據:執行系統優化前建議備份重要文件
- 謹慎操作:注冊表修改等操作可能導致系統不穩定
- 定期執行:建議定期執行磁盤清理和系統文件檢查
- 個性化調整:根據實際需求選擇合適的優化項目
批處理腳本示例
創建一個批處理文件(.bat)來自動化執行常用優化命令:
@echo off
echo 正在執行Windows系統優化...echo 清理系統文件...
cleanmgr /sagerun:1echo 刷新DNS緩存...
ipconfig /flushdnsecho 重置Winsock...
netsh winsock resetecho 掃描系統文件...
sfc /scannowecho 清理Windows映像...
DISM /Online /Cleanup-Image /StartComponentCleanupecho 優化完成!請重啟計算機以使更改生效。
pause