Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows Server

วิธีรีเซ็ตส่วนประกอบ Windows Update เพื่อแก้ไขข้อผิดพลาดการอัปเดต

หากบริการ Windows Update ทำงานไม่ถูกต้อง อัปเดตไม่ได้ดาวน์โหลดหรือติดตั้ง วิธีที่ง่ายและมีประสิทธิภาพที่สุดในการแก้ไขปัญหาบริการ Windows Update คือการกู้คืนการตั้งค่าเดิมของมัน ในบทความนี้ เราจะแสดงวิธีรีเซ็ตการกำหนดค่าของ Windows Update agent และบริการ

ปกติแล้ว เพื่อแก้ไขข้อผิดพลาด Windows Update ผู้ดูแลระบบต้องวิเคราะห์รหัสข้อผิดพลาดในไฟล์ %windir%\WindowsUpdate.log (ใน Windows 10 คุณสามารถรับ WindowsUpdate.log ได้ด้วยวิธีนี้) จำนวนข้อผิดพลาดที่เป็นไปได้ที่ผู้ดูแลระบบอาจเจอเมื่อวิเคราะห์บันทึก Windows update เป็นสิบๆ รหัส (รายการข้อผิดพลาด Windows Update ที่สมบูรณ์) และกระบวนการแก้ไขพวกเขาเป็นเรื่องซับซ้อน เพื่อหลีกเลี่ยงความพยายามที่ไม่จำเป็นและไม่เสียเวลา จะง่ายกว่ามากที่จะรีเซ็ตบริการ Windows Update และ agent ให้กลับสู่สถานะเริ่มต้นโดยสมบูรณ์

การใช้ Windows Update Troubleshooter เพื่อแก้ไขปัญหาการอัปเดต

ก่อนที่จะดำเนินการรีเซ็ตการกำหนดค่า Windows Update เราขอแนะนำอย่างยิ่งให้คุณลองเครื่องมือที่ง่ายกว่าและมีประสิทธิภาพค่อนข้างสูงในการแก้ไขปัญหาในบริการ Windows Update โดยอัตโนมัติโดยใช้ Windows Update Troubleshooter built-in

Windows Update Troubleshooter ถูกสร้างไว้ในแผง Settings สมัยใหม่ใน Windows 10 และ 11 สำหรับรุ่น Windows ก่อนหน้า คุณจะต้องดาวน์โหลดด้วยตนเอง:

  • Windows 11 — Settings → System → Troubleshooter → Other Troubleshooter → Windows Update
  • Windows 10 – wu10.diagcab (https://aka.ms/wudiag) หรือรันเวอร์ชันท้องถิ่นของเครื่องมือ: Start → Settings → Updates and Security → Troubleshoot → Additional Troubleshooters → Windows Updates (Resolve problems that prevent you from updating Windows)
    สำหรับการเข้าถึงเครื่องมือแก้ไขปัญหา Windows อย่างรวดเร็ว คุณสามารถใช้คำสั่ง ms-settings URI: ms-settings:troubleshoot
  • Windows 7 และ Windows 8.1 — WindowsUpdate.diagcab (https://aka.ms/diag_wu)

รอให้ Windows Update Troubleshooter สแกนระบบของคุณและพยายามแก้ไขข้อผิดพลาดในบริการ Windows Update และส่วนประกอบที่เกี่ยวข้องโดยอัตโนมัติ

ในกรณีของผม พบความเสียหายในฐานข้อมูล Windows Update และแก้ไขแล้ว หลังจากนั้นเหลือแค่รีสตาร์ทคอมพิวเตอร์และลองสแกนหาอัปเดต หากอัปเดตไม่ได้ดาวน์โหลดหรือติดตั้ง ให้ดำเนินการขั้นตอนถัดไป

การรีเซ็ต Windows Update Client โดยใช้ PowerShell

คุณสามารถใช้โมดูล PowerShell PSWindowsUpdate เพื่อรีเซ็ต Windows Update agent และบริการ

ติดตั้งโมดูลบนคอมพิวเตอร์ของคุณจากแกลเลอรีสคริปต์ PSGallery:

Install-Module -Name PSWindowsUpdate

เปิดใช้งานการรันสคริปต์ PowerShell:

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned -force

รันคำสั่ง:

Reset-WUComponents –verbose

คำสั่ง Reset-WUComponents หยุดบริการ ลงทะเบียน DLL ใหม่ และทำความสะอาดโฟลเดอร์ C:\Windows\SoftwareDistribution ฯลฯ บันทึกการดำเนินการทั้งหมดพร้อมใช้งาน

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

ค้นหาอัปเดตในแผง Settings หรือค้นหาอัปเดต Windows ที่พร้อมใช้งานโดยใช้ PowerShell:

Get-WUList

การใช้ Reset Windows Update Tool

Reset Windows Update Tool เป็นเครื่องมือที่มีประโยชน์และเรียบง่ายอีกตัวหนึ่งสำหรับการรีเซ็ตการตั้งค่า Windows Update สคริปต์นี้เคยพร้อมใช้งานบน TechNet ผู้เขียนปัจจุบันดูแลที่เก็บบน GitHub (https://github.com/ManuelGil/Script-Reset-Windows-Update-Tool) มาพิจารณาวิธีใช้มัน

มีไฟล์ wureset.exe ที่คอมไพล์แล้ว (C++) หรือสคริปต์แบทช์ทั่วไปสำหรับดาวน์โหลด ผมชอบใช้สคริปต์ cmd

  1. ดาวน์โหลด ResetWUEng.zip และแตกไฟล์
  2. รัน ResetWUEng.cmd เป็นผู้ดูแลระบบ
  3. สคริปต์จะตรวจจับเวอร์ชัน OS ของคุณ (ในตัวอย่างของผมคือ Windows 10) และจะเสนอตัวเลือก 18 แบบต่างๆ บางอย่างไม่เกี่ยวข้องโดยตรงกับการรีเซ็ตการตั้งค่า WU agent แต่อาจมีประโยชน์สำหรับการแก้ไขปัญหา Windows ต่างๆ (ตรวจสอบดิสก์ด้วย chkdsk, ซ่อมแซมอิมเมจ Windows ด้วย DISM, รีเซ็ต Winsock, ล้างไฟล์ชั่วคราว ฯลฯ)
  4. เพื่อรีเซ็ต Windows Update ปกติเพียงพอที่จะใช้ตัวเลือก 2 – Resets the Windows Update Components กด 2 และ Enter
  5. สคริปต์จะดำเนินการทั้งหมดที่เราอธิบายไว้ด้านล่างเมื่อทำการรีเซ็ต Windows Update Agent ด้วยตนเองจาก command line คุณสามารถดูการดำเนินการของสคริปต์โดยเปิดไฟล์ ResetWUEng.cmd ในเครื่องมือแก้ไขข้อความใดๆ และตรวจสอบเนื้อหา ตัวอย่างเช่น ตัวเลือก 2 ส่งคุณไปยังฟังก์ชัน :components
  6. หลังจากเสร็จสิ้นสคริปต์ Reset Windows Update Tool ให้รีสตาร์ทคอมพิวเตอร์ของคุณและตรวจสอบอัปเดตใหม่

สคริปต์ ResetWUEng.cmd เป็นสคริปต์สากลและเหมาะสำหรับรุ่น Windows ทั้งหมดตั้งแต่ Windows XP จนถึง Windows 11

การรีเซ็ตการตั้งค่า Windows Update โดยใช้ Command Prompt

กระบวนการรีเซ็ตการกำหนดค่า Windows Update agent และบริการประกอบด้วยหลายขั้นตอน การดำเนินการทั้งหมดที่อธิบายไว้ทำใน command prompt ที่มีสิทธิ์ผู้ดูแลระบบ ผมเพิ่มคำสั่งทั้งหมดในไฟล์ bat เดียว

โดยใช้สคริปต์นี้ คุณสามารถรีเซ็ตการกำหนดค่า Windows Update และล้างแคชอัปเดตท้องถิ่นได้อย่างสมบูรณ์ สคริปต์นี้ใช้ได้กับทั้งเวิร์กสเตชันที่มี Windows 11/10/8.1/7 และ Windows Server 2022/2019/2016/2012 R2/2008 R2 สคริปต์นี้ช่วยกำจัดข้อผิดพลาด Windows Update ทั่วส่วนใหญ่เมื่อ Windows หยุดดาวน์โหลดอัปเดตใหม่หรือเกิดข้อผิดพลาดระหว่างการติดตั้งอัปเดต

ตรวจสอบว่าการตั้งค่า Windows Update บนคอมพิวเตอร์ของคุณไม่ได้ถูกกำหนดค่าผ่านนโยบายกลุ่มโดเมนหรือท้องถิ่น คุณสามารถใช้เครื่องมือ gpresult หรือ rsop.msc เพื่อแสดงการตั้งค่า GPO ที่ได้ผล หรือคุณสามารถรีเซ็ตการตั้งค่า GPO ท้องถิ่นตามคำแนะนำนี้

มาพิจารณาว่าสคริปต์นี้ทำอะไรทีละขั้นตอน:

  1. หยุดบริการ Windows Update, BITS และบริการเข้ารหัส:
    net stop bits
    net stop wuauserv
    net stop appidsvc
    net stop cryptsvc
    taskkill /im wuauclt.exe /f
  2. ลบไฟล์บริการ qmgr*.dat จากโฟลเดอร์ %ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\:
    Del "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
  3. เปลี่ยนชื่อโฟลเดอร์ระบบ ซึ่งจัดเก็บไฟล์การกำหนดค่าและแคชอัปเดต (หากจำเป็น พวกเขาสามารถใช้เป็นสำรองได้) หลังจากรีสตาร์ทบริการอัปเดต (wuauserv) ไดเรกทอรีเหล่านี้จะถูกสร้างใหม่โดยอัตโนมัติ:
    Ren %systemroot%\SoftwareDistribution SoftwareDistribution.bak
    Ren %systemroot%\system32\catroot2 catroot2.bak
  4. ลบไฟล์ windowsupdate.log เก่า:
    del /f /s /q %windir%\windowsupdate.log
  5. รีเซ็ตสิทธิ์สำหรับบริการ BITS และ Windows Update (หากสิทธิ์บริการถูกเปลี่ยน):
    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. ลงทะเบียนไฟล์ไลบรารีไดนามิก (DLLs) ของระบบที่เกี่ยวข้องกับ BITS และ 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. รีเซ็ตการตั้งค่า Winsock:
    netsh winsock reset
  8. รีเซ็ตการตั้งค่า proxy ของระบบ:
    netsh winhttp reset proxy
  9. ตัวเลือก เมื่อใช้เซิร์ฟเวอร์ WSUS ท้องถิ่น คุณยังสามารถรีเซ็ตการผูกมัดปัจจุบันของไคลเอ็นต์กับเซิร์ฟเวอร์ WSUS ได้โดยการลบพารามิเตอร์ต่อไปนี้ในคีย์รีจิสทรี 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. เริ่มบริการที่หยุดไว้ก่อนหน้านี้:

    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. ตัวเลือก ในบางกรณี คุณจะต้องติดตั้ง/ติดตั้งใหม่เวอร์ชันของ Windows Update Agent (WUA) คุณสามารถตรวจสอบเวอร์ชันไฟล์ Windows Update Agent Wuaueng.dll ปัจจุบันบนคอมพิวเตอร์ของคุณด้วย PowerShell:
    ((Get-Item $Env:windir\system32\Wuaueng.dll).VersionInfo).ProductVersion
    คุณสามารถดาวน์โหลดเวอร์ชันล่าสุดของ Windows Update agent ที่นี่: 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
    ใช้คำสั่งต่อไปนี้เพื่อบังคับติดตั้งใหม่ 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

ตอนนี้คุณเพียงแค่รีสตาร์ทคอมพิวเตอร์ของคุณและรันการซิงโครไนซ์กับ Windows Update หรือ WSUS

wuauclt /resetauthorization /detectnow

จากนั้นไปที่ Windows Update และตรวจสอบว่าไม่มีข้อผิดพลาดขณะตรวจสอบ ดาวน์โหลด และติดตั้งอัปเดต

สคริปต์ reset_windows_update_agent.bat สามารถดาวน์โหลดได้ตามลิงก์ reset_windows_update_agent.zip (ตัวเลือก 9 และ 11 ไม่ได้รวมอยู่ในสคริปต์ เนื่องจากเป็นตัวเลือก) ดาวน์โหลดสคริปต์ แตกไฟล์ และรันเป็นผู้ดูแลระบบ

หาก Windows updates ถูกดาวน์โหลดและติดตั้งอย่างถูกต้อง คุณสามารถลบโฟลเดอร์สำรองได้:

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

หากทุกอย่างล้มเหลว ลองดาวน์โหลดและติดตั้งอัปเดตสะสมล่าสุดสำหรับรุ่น Windows ของคุณด้วยตนเองจาก Microsoft Update Catalog