Sin descripción

Windows Repair.ps1 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. @echo off
  2. :: Check if running as admin
  3. if not "%Administrator%" == "true" (
  4. echo This script must be run as an administrator.
  5. pause
  6. exit
  7. )
  8. :: Set log file
  9. set log_file=%userprofile%\Desktop\WindowsRepair.log
  10. :: Backup existing BCD
  11. echo Backing up existing BCD... >> %log_file%
  12. bcdedit /export c:\BCD_Backup >> %log_file% 2>&1
  13. :: Repair BCD
  14. echo Repairing BCD... >> %log_file%
  15. bcdedit /import c:\BCD_Backup >> %log_file% 2>&1
  16. bcdedit /set {default} bootstatuspolicy ignoreallfailures >> %log_file% 2>&1
  17. bcdedit /set {default} recoveryenabled No >> %log_file% 2>&1
  18. :: Find and mount Windows installer
  19. for /f "tokens=1,2" %%i in ('wmic logicaldisk where drivetype^=3 get caption^, volumename ^| findstr /i "Windows"') do (
  20. set installer_drive=%%i
  21. set installer_name=%%j
  22. )
  23. if not defined installer_drive (
  24. echo No Windows installer found.
  25. pause
  26. exit
  27. )
  28. echo Found Windows installer on drive %installer_drive% with name "%installer_name%".
  29. :: Repair Wim image using the Windows installer
  30. echo Repairing Wim image using the Windows installer... >> %log_file%
  31. dism /image:%installer_drive%\ /cleanup-image /revertpendingactions >> %log_file% 2>&1
  32. dism /online /cleanup-image /scanhealth >> %log_file% 2>&1
  33. if %errorlevel% neq 0 (
  34. echo Wim image repair failed with error code %errorlevel%. Check log for details.
  35. type %log_file%
  36. pause
  37. exit
  38. )
  39. dism /online /cleanup-image /restorehealth /source:%installer_drive%\install.wim >> %log_file% 2>&1
  40. if %errorlevel% neq 0 (
  41. echo Wim image repair failed with error code %errorlevel%. Check log for details.
  42. type %log_file%
  43. pause
  44. exit
  45. )
  46. :: Repair System files using SFC
  47. echo Repairing system files using SFC... >> %log_file%
  48. sfc /scannow /offbootdir=c:\ /offwindir=c:\windows >> %log_file% 2>&1
  49. if %errorlevel% neq 0 (
  50. echo System file repair failed with error code %errorlevel%. Check log for details.
  51. type %log_file%
  52. pause
  53. exit
  54. )
  55. :: Check and repair file system errors using CHKDSK
  56. echo Checking and repairing file system errors using CHKDSK... >> %log_file%
  57. chkdsk /f /r c: >> %log_file% 2>&1
  58. if %errorlevel% neq 0 (
  59. echo File system error repair failed with error code %errorlevel%. Check log for details.
  60. type %log_file%
  61. pause
  62. exit
  63. )
  64. :: Check for and display errors in the log file
  65. echo Checking for errors...
  66. find /i "error" %log_file% > nul && (
  67. echo The following errors were found:
  68. find /i "error" %log_file%
  69. pause
  70. )
  71. echo Repair process complete. Check log for details.
  72. type %log_file%
  73. pause

Powered by TurnKey Linux.