-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchkdsk_scan.cmd
51 lines (46 loc) · 1.72 KB
/
chkdsk_scan.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
@echo off
setlocal enabledelayedexpansion
set "TARGET_DRIVE=%SystemDrive%"
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script requires administrator privileges.
echo Please right-click and select "Run as administrator".
timeout /t 5 /nobreak
exit /b 1
)
cd /d "%SystemDrive%" >nul 2>&1
if %errorlevel% neq 0 (
echo Failed to change to %SystemDrive%
)
for /f "tokens=4 delims=: " %%A in ('fsutil fsinfo volumeinfo %TARGET_DRIVE%^|find "File System Name"') do (
echo %%A | findstr /i /r "^FAT" >nul
if not errorlevel 1 (
echo %TARGET_DRIVE% drive is FAT-based.
echo Repairing %TARGET_DRIVE% file system...
echo This may take a while...
if /i "%TARGET_DRIVE%"=="%SystemDrive%" (
echo y | chkdsk "%TARGET_DRIVE%" /R /X >nul 2>&1
echo Restarting system to complete repairs, please save your work.
timeout /t 30 /nobreak
shutdown /r /t 1 >nul 2>&1
) else (
chkdsk "%TARGET_DRIVE%" /R /X
)
) else (
echo %TARGET_DRIVE% drive is NTFS-based.
echo Repairing %TARGET_DRIVE% file system...
echo This may take a while...
if /i "%TARGET_DRIVE%"=="%SystemDrive%" (
echo y | chkdsk "%TARGET_DRIVE%" /R /X >nul 2>&1
echo Restarting system to complete repairs, please save your work.
echo Run chkdsk "%TARGET_DRIVE%" /sdcleanup after repair finishes.
timeout /t 30 /nobreak
shutdown /r /t 1 >nul 2>&1
) else (
chkdsk "%TARGET_DRIVE%" /R /X
echo Cleaning up unnecessary data structures and unallocated metadata files...
chkdsk "%TARGET_DRIVE%" /sdcleanup
)
)
)
exit /b 0