Greetings,
Lately I have been running CHKDSK /f multiple times to fix issues. At one point I ran it probably 5 to 8 times (this is still quicker than re-install of win)
I think I have a batch file that can do it but it doesnt work as I want it to.
I would like to
1> Run CHKDSK if /F is required then run it on next boot
2> Run CHKDSK /f a specific number of times lets say 5
3> Continue the loop.
4> Or a combination of running 5 times but until there are no errors.
I can add the script below to the start menu and it will work fine. However, I would like it to run only if CHKDSK says to run it with /F perhaps using the CHKDSK error codes below and only stop when no more errors are found or run CHKDSK /F when CHDSK says it cant continue due to errors. I can't fine which exit code would be /F and I looked in the event logs but it does not state. I guess I would just say run unless error 0 but I don't know who to integrate the codes with my batch file.
0 Success, no errors found.
1 Success, CHKDSK has detected and fixed major errors.
2 Success, CHKDSK has detected and fixed minor inconsistencies.
3 Error, CHKDSK could not complete.
@echo off
chkdsk.exe c:
if ERRORLEVEL 2 goto ADD_CHECK
echo.
echo The drive is okay this time.
goto end
:ADD_CHECK
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" /v BootExecute /t REG_MULTI_SZ /d "autocheck autochk /p \??\C:\0autocheck autochk *" /f
echo.
echo The drive has problems and chkdsk will run next boot
shutdown -r -f -t -10
:end
I am sure this can come in handy to other techs. I just don't have the time to sit looking at the screen.
Eventually I will tie this in with defrag after chkdsk fixes all errors.
Thank you
Lately I have been running CHKDSK /f multiple times to fix issues. At one point I ran it probably 5 to 8 times (this is still quicker than re-install of win)
I think I have a batch file that can do it but it doesnt work as I want it to.
I would like to
1> Run CHKDSK if /F is required then run it on next boot
2> Run CHKDSK /f a specific number of times lets say 5
3> Continue the loop.
4> Or a combination of running 5 times but until there are no errors.
I can add the script below to the start menu and it will work fine. However, I would like it to run only if CHKDSK says to run it with /F perhaps using the CHKDSK error codes below and only stop when no more errors are found or run CHKDSK /F when CHDSK says it cant continue due to errors. I can't fine which exit code would be /F and I looked in the event logs but it does not state. I guess I would just say run unless error 0 but I don't know who to integrate the codes with my batch file.
0 Success, no errors found.
1 Success, CHKDSK has detected and fixed major errors.
2 Success, CHKDSK has detected and fixed minor inconsistencies.
3 Error, CHKDSK could not complete.
@echo off
chkdsk.exe c:
if ERRORLEVEL 2 goto ADD_CHECK
echo.
echo The drive is okay this time.
goto end
:ADD_CHECK
reg ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" /v BootExecute /t REG_MULTI_SZ /d "autocheck autochk /p \??\C:\0autocheck autochk *" /f
echo.
echo The drive has problems and chkdsk will run next boot
shutdown -r -f -t -10
:end
I am sure this can come in handy to other techs. I just don't have the time to sit looking at the screen.
Eventually I will tie this in with defrag after chkdsk fixes all errors.
Thank you

Help
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.



Back to top









