Computer >> Hướng Dẫn Máy Tính >  >> Hệ Thống >> Máy Chủ Windows

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Nếu dịch vụ Windows Update không hoạt động đúng, cập nhật không được tải xuống hoặc cài đặt, thì cách dễ dàng và hiệu quả nhất để giải quyết vấn đề với dịch vụ Windows Update là khôi phục cài đặt gốc của nó. Trong bài viết này, chúng tôi sẽ chỉ cho bạn cách đặt lại cấu hình agent và dịch vụ Windows Update.

Thường thì, để debug lỗi Windows Update, quản trị viên cần phân tích mã lỗi trong file %windir%\WindowsUpdate.log (trong Windows 10 bạn có thể lấy WindowsUpdate.log theo cách này). Số lượng lỗi có thể gặp khi phân tích log cập nhật Windows là hàng chục (danh sách đầy đủ lỗi Windows Update) và quy trình giải quyết chúng không tầm thường. Để tránh nỗ lực không cần thiết và không lãng phí thời gian, dễ dàng hơn nhiều là đặt lại hoàn toàn dịch vụ Windows Update và agent về trạng thái mặc định.

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Sử dụng Windows Update Troubleshooter để khắc phục sự cố cập nhật

Trước khi tiến hành đặt lại cấu hình Windows Update, chúng tôi khuyên bạn nên trước tiên thử công cụ đơn giản và khá hiệu quả để tự động sửa vấn đề trong dịch vụ Windows Update bằng Windows Update Troubleshooter tích hợp sẵn.

Windows Update Troubleshooter đã được tích hợp sẵn vào bảng cài đặt Settings hiện đại trong Windows 10 và 11. Đối với các phiên bản Windows trước, bạn sẽ phải tải xuống thủ công:

  • Windows 11 — Settings -> System -> Troubleshooter -> Other Troubleshooter -> Windows Update; Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật
  • Windows 10 – wu10.diagcab (https://aka.ms/wudiag) hoặc chạy phiên bản cục bộ của công cụ: Start -> Settings -> Updates and Security -> Troubleshoot -> Additional Troubleshooters -> Windows Updates (Resolve problems that prevent you from updating Windows);Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật Để truy cập nhanh công cụ khắc phục sự cố Windows, bạn có thể dùng lệnh URI ms-settings: ms-settings:troubleshoot
  • Windows 7 và Windows 8.1 — WindowsUpdate.diagcab (https://aka.ms/diag_wu).

Đợi Windows Update Troubleshooter quét hệ thống và cố gắng tự động sửa bất kỳ lỗi nào trong Windows Update và các thành phần liên quan.

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Trong trường hợp của tôi, sự hỏng hóc trong cơ sở dữ liệu Windows Update được tìm thấy và sửa chữa. Sau đó, chỉ cần khởi động lại máy tính và thử quét cập nhật. Nếu cập nhật không được tải xuống hoặc cài đặt, hãy chuyển sang bước tiếp theo.

Đặt lại Windows Update Client bằng PowerShell

Bạn có thể dùng module PowerShell PSWindowsUpdate để đặt lại agent và dịch vụ Windows Update.

Cài đặt module trên máy tính của bạn từ thư viện script PSGallery:

Install-Module -Name PSWindowsUpdate

Bật thực thi script PowerShell:

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned -force

Chạy lệnh:

Reset-WUComponents –verbose

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Lệnh Reset-WUComponents dừng dịch vụ, đăng ký lại DLL, và dọn dẹp thư mục C:\Windows\SoftwareDistribution, v.v. Log đầy đủ các hành động có sẵn.

VERBOSE: Background Intelligent Transfer Service (BITS)
VERBOSE: Windows Update (wuauserv)
VERBOSE: Application Identity (appidsvc)
VERBOSE: Cryptographic Services (cryptsvc)
Step 2: Delete the qmgr*.dat files
Step 3: Backup software distribution folders
VERBOSE: Renaming Software Distribution folder to C:\Windows\SoftwareDistribution.bak
VERBOSE: Renaming CatRoot folder to C:\Windows\System32\Catroot2.bak
Step 4: Remove old Windows Update logs
VERBOSE: Deleting the C:\Windows\WindowsUpdate.log files.
Step 5: Reset Windows Update services
VERBOSE: Reset BITS service
VERBOSE: Reset Windows Update service
Step 6: Reregister dll's
VERBOSE: regsvr32.exe / s atl.dll
VERBOSE: regsvr32.exe / s urlmon.dll
VERBOSE: regsvr32.exe / s mshtml.dll
VERBOSE: regsvr32.exe / s shdocvw.dll
VERBOSE: regsvr32.exe / s browseui.dll
VERBOSE: regsvr32.exe / s jscript.dll
VERBOSE: regsvr32.exe / s vbscript.dll
VERBOSE: regsvr32.exe / s scrrun.dll
VERBOSE: regsvr32.exe / s msxml.dll
VERBOSE: regsvr32.exe / s msxml3.dll
VERBOSE: regsvr32.exe / s msxml6.dll
VERBOSE: regsvr32.exe / s actxprxy.dll
VERBOSE: regsvr32.exe / s softpub.dll
VERBOSE: regsvr32.exe / s wintrust.dll
VERBOSE: regsvr32.exe / s dssenh.dll
VERBOSE: regsvr32.exe / s rsaenh.dll
VERBOSE: regsvr32.exe / s gpkcsp.dll
VERBOSE: regsvr32.exe / s sccbase.dll
VERBOSE: regsvr32.exe / s slbcsp.dll
VERBOSE: regsvr32.exe / s cryptdlg.dll
VERBOSE: regsvr32.exe / s oleaut32.dll
VERBOSE: regsvr32.exe / s ole32.dll
VERBOSE: regsvr32.exe / s shell32.dll
VERBOSE: regsvr32.exe / s initpki.dll
VERBOSE: regsvr32.exe / s wuapi.dll
VERBOSE: regsvr32.exe / s wuaueng.dll
VERBOSE: regsvr32.exe / s wuaueng1.dll
VERBOSE: regsvr32.exe / s wucltui.dll
VERBOSE: regsvr32.exe / s wups.dll
VERBOSE: regsvr32.exe / s wups2.dll
VERBOSE: regsvr32.exe / s wuweb.dll
VERBOSE: regsvr32.exe / s qmgr.dll
VERBOSE: regsvr32.exe / s qmgrprxy.dll
VERBOSE: regsvr32.exe / s wucltux.dll
VERBOSE: regsvr32.exe / s muweb.dll
VERBOSE: regsvr32.exe / s wuwebv.dll
Step 7: Reset WinSock
VERBOSE: netsh winsock reset
Step 8: Reset Proxy
VERBOSE: netsh winhttp reset proxy
Step 9: Start Windows Update services
VERBOSE: Cryptographic Services (cryptsvc)
VERBOSE: Application Identity (appidsvc)
VERBOSE: Windows Update (wuauserv)
VERBOSE: Background Intelligent Transfer Service (BITS)
Step 10: Start Windows Update services
VERBOSE: wuauclt /resetauthorization /detectnow

Tìm kiếm cập nhật trong bảng Settings, hoặc tìm kiếm Windows update có sẵn bằng PowerShell:

Get-WUList

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Sử dụng Reset Windows Update Tool

Reset Windows Update Tool là một công cụ hữu ích và đơn giản khác để đặt lại cài đặt Windows Update. Script này từng có sẵn trên TechNet. Tác giả hiện duy trì kho lưu trữ trên GitHub (https://github.com/ManuelGil/Script-Reset-Windows-Update-Tool). Hãy xem cách sử dụng nó.

File wureset.exe đã biên dịch (C++) hoặc script batch thông thường được cung cấp để tải xuống. Tôi thích dùng script cmd.

  1. Tải xuống ResetWUEng.zip và giải nén;
  2. Chạy ResetWUEng.cmd với quyền admin;
  3. Script sẽ phát hiện phiên bản OS của bạn (trong ví dụ của tôi, là Windows 10) và sẽ cung cấp 18 tùy chọn khác nhau. Một số trong số đó không liên quan trực tiếp đến đặt lại cài đặt WU agent, nhưng có thể hữu ích để sửa các vấn đề Windows khác (kiểm tra đĩa với chkdsk, sửa hình ảnh Windows với DISM, đặt lại Winsock, xóa file tạm, v.v.);Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật
  4. Để đặt lại Windows Update, thường chỉ cần dùng tùy chọn 2 – Resets the Windows Update Components. Nhấn 2 và Enter;Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật
  5. Script sẽ tự động thực hiện tất cả các hành động mà chúng tôi đã mô tả bên dưới khi đặt lại thủ công Windows Update Agent từ dòng lệnh; Bạn có thể xem các hành động script đã thực hiện bằng cách mở file ResetWUEng.cmd trong bất kỳ trình soạn thảo văn bản nào và kiểm tra nội dung của nó. Ví dụ, tùy chọn 2 gửi bạn đến hàm :components. Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật
  6. Sau khi hoàn thành script Reset Windows Update Tool, khởi động lại máy tính và kiểm tra cập nhật mới.

Script ResetWUEng.cmd là univerzический và phù hợp cho tất cả phiên bản Windows từ Windows XP đến Windows 11.

Đặt lại cài đặt Windows Update bằng Command Prompt

Quy trình đặt lại cấu hình agent và dịch vụ Windows Update bao gồm một số bước. Tất cả các thao tác được mô tả đều được thực hiện trong command prompt nâng cao. Tôi đã thêm tất cả các lệnh vào một file bat đơn lẻ.

Sử dụng script này, bạn có thể đặt lại hoàn toàn cấu hình Windows Update và xóa bộ nhớ đệm cập nhật cục bộ. Script này áp dụng cho cả máy trạm với Windows 11/10/8.1/7 và Windows Server 2022/2019/2016/2012 R2/2008 R2. Script này giúp loại bỏ hầu hết các lỗi Windows Update điển hình khi Windows ngừng tải xuống bản cập nhật mới hoặc lỗi xuất hiện trong quá trình cài đặt cập nhật.

Đảm bảo cài đặt Windows Update trên máy tính của bạn không được cấu hình bằng domain hoặc local group policy. Bạn có thể dùng công cụ gpresult hoặc rsop.msc để hiển thị cài đặt GPO kết quả. Hoặc bạn có thể đặt lại cài đặt GPO cục bộ theo hướng dẫn này.

Hãy xem script này làm gì từng bước:

  1. Dừng dịch vụ Windows Update, BITS, và dịch vụ mật mã:
    net stop bits
    net stop wuauserv
    net stop appidsvc
    net stop cryptsvc
    taskkill /im wuauclt.exe /f
  2. Xóa file dịch vụ qmgr*.dat từ thư mục %ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\:
    Del "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
  3. Đổi tên thư mục hệ thống, nơi lưu trữ file cấu hình và bộ nhớ đệm cập nhật (nếu cần, chúng có thể dùng làm bản sao lưu). Sau khi khởi động lại dịch vụ cập nhật (wuauserv), các thư mục này sẽ được tạo lại tự động:
    Ren %systemroot%\SoftwareDistribution SoftwareDistribution.bak
    Ren %systemroot%\system32\catroot2 catroot2.bak
  4. Xóa file windowsupdate.log cũ:
    del /f /s /q %windir%\windowsupdate.log
  5. Đặt lại quyền cho dịch vụ BITS và Windows Update (nếu quyền dịch vụ đã bị thay đổi):
    sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
    sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
    sc.exe sdset cryptsvc D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
    sc.exe sdset trustedinstaller D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
  6. Đăng ký lại file thư viện động (DLL) hệ thống liên quan đến BITS và Windows Update:
    cd /d %windir%\system32
    regsvr32.exe /s atl.dll
    regsvr32.exe /s urlmon.dll
    regsvr32.exe /s mshtml.dll
    regsvr32.exe /s shdocvw.dll
    regsvr32.exe /s browseui.dll
    regsvr32.exe /s jscript.dll
    regsvr32.exe /s vbscript.dll
    regsvr32.exe /s scrrun.dll
    regsvr32.exe /s msxml.dll
    regsvr32.exe /s msxml3.dll
    regsvr32.exe /s msxml6.dll
    regsvr32.exe /s actxprxy.dll
    regsvr32.exe /s softpub.dll
    regsvr32.exe /s wintrust.dll
    regsvr32.exe /s dssenh.dll
    regsvr32.exe /s rsaenh.dll
    regsvr32.exe /s gpkcsp.dll
    regsvr32.exe /s sccbase.dll
    regsvr32.exe /s slbcsp.dll
    regsvr32.exe /s cryptdlg.dll
    regsvr32.exe /s oleaut32.dll
    regsvr32.exe /s ole32.dll
    regsvr32.exe /s shell32.dll
    regsvr32.exe /s initpki.dll
    regsvr32.exe /s wuapi.dll
    regsvr32.exe /s wuaueng.dll
    regsvr32.exe /s wuaueng1.dll
    regsvr32.exe /s wucltui.dll
    regsvr32.exe /s wups.dll
    regsvr32.exe /s wups2.dll
    regsvr32.exe /s wuweb.dll
    regsvr32.exe /s qmgr.dll
    regsvr32.exe /s qmgrprxy.dll
    regsvr32.exe /s wucltux.dll
    regsvr32.exe /s muweb.dll
    regsvr32.exe /s wuwebv.dll
  7. Đặt lại cài đặt Winsock:
    netsh winsock reset
  8. Đặt lại cài đặt proxy hệ thống:
    netsh winhttp reset proxy
  9. Tùy chọn. Khi sử dụng máy chủ WSUS cục bộ, bạn cũng có thể đặt lại liên kết hiện tại của client với máy chủ WSUS bằng cách xóa các tham số sau trong khóa registry HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate:
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AccountDomainSid /f
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v PingID /f
    REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f
    REG DELETE "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v TargetGroup /f
    REG DELETE "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v WUServer /f
    REG DELETE "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v WUStatusServer /f
  10. Khởi động lại các dịch vụ đã dừng trước đó:
    
    sc.exe config wuauserv start= auto
    sc.exe config bits start= delayed-auto
    sc.exe config cryptsvc start= auto
    sc.exe config TrustedInstaller start= demand
    sc.exe config DcomLaunch start= auto
    net start bits
    net start wuauserv
    net start appidsvc
    net start cryptsvc
  11. Tùy chọn. Trong một số trường hợp, bạn sẽ cần cài đặt/cài đặt lại phiên bản Windows Update Agent (WUA). Bạn có thể kiểm tra phiên bản file Windows Update Agent Wuaueng.dll hiện tại trên máy tính của bạn bằng PowerShell:
    ((Get-Item $Env:windir\system32\Wuaueng.dll).VersionInfo).ProductVersion
    Bạn có thể tải phiên bản mới nhất của Windows Update agent tại đây: https://support.microsoft.com/en-us/kb/949104.
    Windows 8.1 – 7.9.9600
    Windows 8 – 7.8.9200.16693
    Windows 7 – 7.6.7600.256
    Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật Dùng các lệnh sau để buộc cài đặt lại Windows Update Agent: Windows 7 x86: WindowsUpdateAgent-7.6-x86.exe /quiet /norestart /wuforce
    Windows 7 x64: WindowsUpdateAgent-7.6-x64.exe /quiet /norestart /wuforce

Bây giờ bạn chỉ cần khởi động lại máy tính và chạy đồng bộ với Windows Update hoặc WSUS.

wuauclt /resetauthorization /detectnow

Sau đó vào Windows Update và đảm bảo không có lỗi khi kiểm tra, tải xuống và cài đặt cập nhật.

Script reset_windows_update_agent.bat có thể được tải xuống theo link reset_windows_update_agent.zip (tùy chọn 9 và 11 không được bao gồm trong script vì chúng là tùy chọn). Tải script, giải nén, và chạy với quyền admin.

Cách đặt lại thành phần Windows Update để sửa lỗi cập nhật

Nếu Windows update được tải xuống và cài đặt đúng cách, bạn có thể xóa thư mục backup:

Ren %systemroot%\SoftwareDistribution SoftwareDistribution.bak
Ren %systemroot%\system32\catroot2 catroot2.bak

Nếu mọi cách khác đều thất bại, hãy thử tải xuống và cài đặt thủ công bản cập nhật tích lũy mới nhất cho phiên bản Windows của bạn từ Microsoft Update Catalog.