If you’re experiencing system issues or errors related to Windows components, running a script to check and fix your OS system components can help. Below is a PowerShell script that automates this process:
Script
SC config trustedinstaller start=auto
net stop bits
net stop wuauserv
net stop msiserver
net stop cryptsvc
net stop appidsvc
Ren %Systemroot%\SoftwareDistribution SoftwareDistribution.old
Ren %Systemroot%\System32\catroot2 catroot2.old
regsvr32.exe /s atl.dll
regsvr32.exe /s urlmon.dll
regsvr32.exe /s mshtml.dll
netsh winsock reset
netsh winsock reset proxy
rundll32.exe pnpclean.dll,RunDLL_PnpClean /DRIVERS /MAXCLEAN
dism /Online /Cleanup-image /ScanHealth
dism /Online /Cleanup-image /CheckHealth
dism /Online /Cleanup-image /RestoreHealth
dism /Online /Cleanup-image /StartComponentCleanup
Sfc /ScanNow
net start bits
net start wuauserv
net start msiserver
net start cryptsvc
net start appidsvc
This PowerShell script is designed to diagnose and repair common Windows system issues. It performs a series of checks and fixes to ensure optimal system health.
Key Actions Performed by the Script:
- Starts the TrustedInstaller Service: This service is crucial for system updates and installations.
- Stops Windows Update Services: This prevents interference during the repair process.
- Deletes Temporary System Files: Removes old software distribution and catroot2 folders, which can sometimes cause issues.
- Re-registers DLLs: Re-registers essential DLLs to resolve potential errors.
- Resets Winsock Catalog: Fixes Winsock-related issues that might disrupt network connectivity.
- Cleans up Device Driver Installation: Removes old driver installations that could cause conflicts.
- Scans and Repairs System Files: Uses the DISM tool to check and repair system files for corruption.
- System File Checker: Scans and repairs system files for integrity.
- Restarts Stopped Services: Restores the stopped services to their original state.
How to Use the Script:
- Create a New Text File: Open a text editor like Notepad and paste the script code.
- Save as a .bat File: Save the file with a
.bat
extension (e.g.,system_repair.bat
). - Run the Script: Double-click the saved
.bat
file to execute the script.
Important Considerations:
- Administrative Privileges: You’ll need to run the script with administrative privileges.
- System Restart: The script might prompt you to restart your system after the repair process.
- Backup: It’s always wise to create a system restore point or backup your important data before running significant system repair scripts.