-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_autorepair.cmd
111 lines (98 loc) · 3.23 KB
/
win_autorepair.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
@ECHO OFF
:START
CLS
SETLOCAL ENABLEDELAYEDEXPANSION DISABLEDELAYEDEXPANSION
SET root_disk=%~d0
SET root_path=%~dp0
ECHO This script will help you with OS repairing.
GOTO INFO
:INFO
ECHO Start working...
CHCP
ECHO SystemDrive: "%SystemDrive%", WINDIR: "%WINDIR%"
ECHO PATH: [%PATH%]
CD /D "%root_path%"
GOTO WinRE
@REM GOTO DiskPart
:DiskPart
@REM Can be broken below, passing
ECHO ******************
ECHO DiskPart info > "%root_disk%:\DiskPart.log" | TYPE "%root_disk%:\DiskPart.log"
DISKPART
LIST DISK
SELECT DISK 1
DETAIL DISK
LIST VOLUME
SELECT VOLUME "C:\"
DETAIL VOLUME
LIST PARTITION
SELECT PARTITION "1"
DETAIL PARTITION
EXIT
GOTO WinRE
:WinRE
ECHO ******************
ECHO Windows Recovery Environment (WinRE) info
reagentc.exe /info > "%root_disk%:\reagentc.log" | TYPE "%root_disk%:\reagentc.log"
ECHO ***
reagentc.exe /enable >> "%root_disk%:\reagentc.log" | TYPE "%root_disk%:\reagentc.log"
GOTO SFC_p1
:SFC_p1
ECHO ******************
ECHO SFC (part 1)
SFC /?
ECHO ***
SFC.exe /VERIFYONLY
ECHO ***
SFC.exe /SCANNOW
ECHO ***
NOTEPAD.exe "%WINDIR%\Logs\CBS\CBS.log"
GOTO CHKDSK
:CHKDSK
ECHO ******************
ECHO CHKDSK
ENDLOCAL && SETLOCAL ENABLEDELAYEDEXPANSION
@REM https://serverfault.com/a/268814
SET /a count=1
SET "delimiter=, "
SET "labels_free=Z Y X W V U T S R Q P O N M L K J I H G F E D C B A "
FOR /F "skip=1 tokens=1 delims= " %%a IN ('WMIC.exe LOGICALDISK GET "Caption"') DO (
@REM Sanitizing newline and non-labels
@REM https://newbedev.com/how-to-see-if-a-string-contains-a-substring-using-batch
ECHO [%count%] Detected label "%%a", repairing | FIND ":"
SET /a count=%count%+1
SET "labels_used=!labels_used!%%a\%delimiter%"
SET "labels_free=!labels_free:%%a =!"
CHKDSK.exe "%SystemDrive%:\" /F /R /OfflineScanAndFix
ECHO ***
ECHO SFC (part 1)
SFC.exe /SCANFILE="%SystemDrive%:\windows\system32\kernel32.dll" /OFFBOOTDIR="%SystemDrive%:\" /OFFWINDIR="%SystemDrive%:\windows\" /OFFLOGFILE="%root_disk%:\SFC.log"
SFC.exe /SCANFILE="%SystemDrive%:\windows\system32\winload.efi" /OFFBOOTDIR="%SystemDrive%:\" /OFFWINDIR="%SystemDrive%:\windows\" /OFFLOGFILE="%root_disk%:\SFC.log"
ECHO ******************
ECHO DISM
@REM DISM.exe /Online /Cleanup-Image /CheckHealth ...
DISM.exe /Cleanup-Image /CheckHealth /LogLevel:4 /ScratchDir:"%root_disk%:\" /Image:"%SystemDrive%:\" /LogPath:"%root_disk%:\DISM_Check.log"
ECHO ***
DISM.exe /Cleanup-Image /ScanHealth /LogLevel:4 /ScratchDir:"%root_disk%:\" /Image:"%SystemDrive%:\" /LogPath:"%root_disk%:\DISM_Scan.log"
ECHO ***
DISM.exe /Cleanup-Image /RestoreHealth /LogLevel:4 /ScratchDir:"%root_disk%:\" /Image:"%SystemDrive%:\" /LogPath:"%root_disk%:\DISM_Restore.log"
@REM For PowerShell: Repair-WindowsImage -Online -CheckHealth
@REM DISM.exe /?
@REM NOTEPAD.exe "%WINDIR%\Logs\DISM\dism.log"
)
SET labels_used=%labels_used:~0,-8%
SET labels
GOTO BootRec
:BootRec
ECHO ******************
ECHO BootRec (WinRE only!)
@REM req. Diskpart Assign=Z
BootRec.exe /ScanOS > "%root_disk%:\BootRec.log" | TYPE "%root_disk%:\BootRec.log"
ECHO ***
BootRec.exe /FixMBR /FixBoot /RebuildBCD >> "%root_disk%:\BootRec.log" | TYPE "%root_disk%:\BootRec.log"
:END
ECHO ******************
ECHO Done working.
PAUSE
ENDLOCAL
EXIT /B %ERRORLEVEL%