Hi,
I'm trying to write a batch file that I can use to schedule automatic CHKDSK and DEFRAG of my disks, but I'm having some problems.
Here is my code:
The first problem is that I cannot tell CHKDSK to fix errors on the C: drive because it's being used by Windows, so it prompts me whether I want to schedule it during my next boot...
Since it's running in a batch file, nobody will be there to press Y or N. Is there a way to automatically default to Y?
My next problem is checking the return code from CHKDSK. For some of my disks it returns 0; but for others it returns 2 which appears to mean a Warning, but not an Error; then sometimes I see an ERRORLEVEL of 3 when there are actual Errors found. Does anyone know what all the return codes are for CHKDSK and what they mean (how serious they are)?
I get this problem on the C: drive:
But no matter how many times I run CHKDSK with /F /R (and reboot), the problem still appears.
I did some research about this problem and found lots of webpages talking about it. From what I can tell, it's an NTFS bug, Microsoft has no idea how to fix it, and they tell everyone to just ignore it because it's not a real problem...
Well that's what I'd like to do -- just ignore it; but it also returns ERRORLEVEL 3 which it what I get when CHKDSK actually finds "real" problems on the disk. So how can I automate CHKDSK and tell it to ignore the above error, but to re-run with /F /R for real problems?
I'm trying to write a batch file that I can use to schedule automatic CHKDSK and DEFRAG of my disks, but I'm having some problems.
Here is my code:
Code:
@ECHO OFF
SETLOCAL
IF "%1"=="" GOTO Syntax
@ECHO =====================================================================
@ECHO %0 started at the following date and time:
DATE /T
TIME /T
@ECHO =====================================================================
:LoopStart
@ECHO ========================= Checking drive %1 =========================
CHKDSK %1 /V
IF ERRORLEVEL 1 (
@ECHO ********** CHKDSK returned Error Level = %ERRORLEVEL%
@ECHO ********** Errors found on drive %1 !! Re-Running CHKDSK with /F /R switches.
CHKDSK %1 /F /R /V
) ELSE (
@ECHO ==================== Defragmenting drive %1 ====================
DEFRAG %1 -V
)
SHIFT
IF NOT "%1"=="" GOTO LoopStart
@ECHO =====================================================================
GOTO End
:Syntax
@ECHO Syntax: %0 {drive} [{drive}...]
@ECHO .
@ECHO Example: %0 C: D: E:
:End
ENDLOCAL
Since it's running in a batch file, nobody will be there to press Y or N. Is there a way to automatically default to Y?
My next problem is checking the return code from CHKDSK. For some of my disks it returns 0; but for others it returns 2 which appears to mean a Warning, but not an Error; then sometimes I see an ERRORLEVEL of 3 when there are actual Errors found. Does anyone know what all the return codes are for CHKDSK and what they mean (how serious they are)?
I get this problem on the C: drive:
Code:
C:\>CHKDSK c: /V
The type of the file system is NTFS.
Volume label is Main_OS.
WARNING! F parameter not specified.
Running CHKDSK in read-only mode.
CHKDSK is verifying files (stage 1 of 3)...
File verification completed.
CHKDSK is verifying indexes (stage 2 of 3)...
Index verification completed.
Detected minor inconsistencies on the drive. This is not a corruption.
CHKDSK is verifying security descriptors (stage 3 of 3)...
Cleaning up 3 unused index entries from index $SII of file 9.
Cleaning up 3 unused index entries from index $SDH of file 9.
Cleaning up 3 unused security descriptors.
Security descriptor verification completed.
[b]Correcting errors in the Volume Bitmap.
Windows found problems with the file system.
Run CHKDSK with the /F (fix) option to correct these.[/b]
20482874 KB total disk space.
4613528 KB in 30927 files.
9340 KB in 2818 indexes.
0 KB in bad sectors.
100750 KB in use by the system.
65536 KB occupied by the log file.
15759256 KB available on disk.
4096 bytes in each allocation unit.
5120718 total allocation units on disk.
3939814 allocation units available on disk.
C:\>ECHO %ERRORLEVEL%
3
I did some research about this problem and found lots of webpages talking about it. From what I can tell, it's an NTFS bug, Microsoft has no idea how to fix it, and they tell everyone to just ignore it because it's not a real problem...
Well that's what I'd like to do -- just ignore it; but it also returns ERRORLEVEL 3 which it what I get when CHKDSK actually finds "real" problems on the disk. So how can I automate CHKDSK and tell it to ignore the above error, but to re-run with /F /R for real problems?