Przeglądaj źródła

Upload files to ''

nathan 2 lat temu
rodzic
commit
6e7a1cd8e9
1 zmienionych plików z 85 dodań i 0 usunięć
  1. 85
    0
      Windows Repair.ps1

+ 85
- 0
Windows Repair.ps1 Wyświetl plik

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

Powered by TurnKey Linux.