batch to run chkdsk on all local drives?

  • Thread starter Pegasus \(MVP\)
  • Start date
P

Pegasus \(MVP\)

Tyler Durden said:
Is possible? tried to find that, with no success. The batch should find
all available local drives and do a chkdsk /f only to the next restart.

Any help would be appreciated. Thanks!

You could run this command to check your NTFS partitions:
chkntfs /d
 
T

Tyler Durden

Is possible? tried to find that, with no success. The batch should find all
available local drives and do a chkdsk /f only to the next restart.

Any help would be appreciated. Thanks!
 
T

Tyler Durden

It must run on all local drives, including removable and fat32. Also, the
chkntfs /d run on volumes with dirty bit set, and errors could exist even
when this bit is not set.
 
C

charles

Is possible? tried to find that, with no success. The batch should find all
available local drives and do a chkdsk /f only to the next restart.

Any help would be appreciated. Thanks!

@echo off
for %%x in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%x:\ echo.y|chkdsk %%x: /f)
 
P

Pegasus \(MVP\)

Have you changed your requirements? You initially wanted something that runs
chkdsk on the next restart. The current solution will run chkdsk immediately
on all non-locked drives.
 
T

Tyler Durden

In a one-liner! But another question arises: since seems that the echo.y is
valid on english systems, how always answer 'yes' on any OS language?

Thank you charles.
 
P

Pegasus \(MVP\)

Al Dunbar said:
But that would process mapped drives in addition to local ones. Perhaps
this could be avoided by unmapping drives first, i.e.:


/Al

This has nothing to do with the subject but your PC clock appears to be two
hours fast, or else your time zone is set incorrectly.
 
A

Al Dunbar

charles said:
@echo off
for %%x in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%x:\ echo.y|chkdsk %%x: /f)

But that would process mapped drives in addition to local ones. Perhaps this
could be avoided by unmapping drives first, i.e.:
@echo off
net use * /del
for %%x in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%x:\ echo.y|chkdsk %%x: /f)

/Al
 
T

Tyler Durden

What would be the best/fastest option and why?

1) Set dirty bit on on all 'fsutil fsinfo drives', preceded by chkntfs /d
and chkntfs /t:0 (leaving all the work to the restart)
2) Chkdsk /f on all unlocked volumes immediately, leaving the only locked
volumes to the next restart
 
T

Tyler Durden

Pegasus, just to give a little more detail. This script code will be at the
end of another, and would run or not according to a CHOICE %errorlevel%
right before. The whole script is used at a computer service shop and to
regular maintenance of workstations, that can vary greatly in languages (so
the issue with echoing 'y' as answer) and drive letters.
 
P

Pegasus \(MVP\)

It seems there is no need for you to defer the chkdsk command until the next
reboot.

To avoid having to pipe "Y" into the chkdsk command you could use my
registry preset approach. Alternatively you can probably use this batch file
to find the "Y" equivalent in different language installations. I haven't
tested it on non-English machines.
@echo off
for /F "delims=" %%a in ('copy /? ^| find /i "copycmd"') do set line=%%a
call :Sub %line%
set Yes=%Yes:~1,1%
echo Switch=%Yes%
goto :eof

:Sub
set Yes=%1
if "%Yes%"=="" goto :eof
if %Yes:~0,1%==/ goto :eof
shift
goto :sub
 
T

Tyler Durden

Thank you for the 'yes' approach. The following is a code to set dirty bit
on all drives listed by fsutil, could be smaller but works fine. Method
fails to check fat32 volumes, so the chkdsk script from charles seems
better.

@ECHO OFF

CHKNTFS /D
CHKNTFS /T:0

SETLOCAL ENABLEDELAYEDEXPANSION
SET Drives=

FOR /F "skip=1 tokens=1,2 delims=\ " %%A IN ('FSUTIL FSINFO DRIVES ^| MORE
/E /T0') DO (
IF "%%B"=="" (
SET Drives=!Drives! %%A
) ELSE (
SET Drives=%%B
)
)

FOR %%A in (%Drives%) DO FSUTIL DIRTY SET %%A
 
A

Al Dunbar

Pegasus (MVP) said:
This has nothing to do with the subject but your PC clock appears to be
two hours fast, or else your time zone is set incorrectly.

Thanks for pointing this out. I have actually moved two timezones east for a
couple of months, and somehow neglected this little detail. I'll try to
remember to fix that a bit later.

/Al (writing at 01:18)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top