Scheduling Boot-time CHKDSK

I see very little information out there regarding what I'm trying to do so I took the liberty of trying it out myself, but I want some expert advice before I go and deploy this method to multiple computers.

What I'm trying to accomplish is scheduling CHKDSK to run at next boot on any given machine, this way the system volume can be checked safely and automatically.

What I have learned is that Windows 2003 forces a CHKDSK on all volumes that have the NTFS dirty bit set. What I have also learned is that you can manually set the dirty bit. Now this is where information seems to be non-existent, at least not on the first few pages of google searches.

Is it safe to purposefully set the dirty bit on all local volumes of a computer so that they have to run a CHKDSK at next boot? I have tested this on a virtual machine and it seems that it worked fine, the Event Log shows normal CHKDSK functionality output.

The script I would use would look something like:

c:\windows\system32\fsutil dirty set c:
c:\windows\system32\fsutil dirty set d:
c:\windows\system32\shutdown /f/r

Open in new window

In this example the C: and D: volumes would have their dirty bit set, then a forced shutdown and reboot would occur. Since the dirty bit was set on both volumes Windows Server 2003 performs a CHKDSK /f on both.

If you can, please advise me of the CONS of this method, all I'm seeing are PROS (Which is common when researching something new). Thanks.

P.S. I am unaware if this works on Server 2008/R2/Windows 7 environments. Everything I have researched only talks about Server 2003. (Edit: It looks like I can use "chkntfs /c [drive]" to accomplish this on a newer OS)

Bonus 100 points to the person that can show me how to make a batch file that can run a FOR loop to check for valid drives. (Most likely using 'wmic logicaldisk get name') To avoid having to create hundreds of unique script files tailored to each machine. I'm very bad at FOR loops.
Who is Participating?
noxchoGlobal Support CoordinatorCommented:
Actually if your systems have only C: and D: partitions then you do not need to set this dirty bit at all. Simply CHKDSK c:/r and CHKDSK d:/r and during next start it will take care of checking.
But your method is absolutely ok as well.
Sumit GuptaSystem and Virtualization EngineerCommented:
Basically if you just want to run chkdsk /f or maybe chkdsk /r on bootup every time, you can set it to run when you shut down rather than trying to make it work in HKLM\SYSTEM\CurrentControlSet\Control\Session Manager.

Here is how:

Create a file C:\WINDOWS\system32\confirm.txt with JUST y in it.

Then create C:\WINDOWS\system32\Chkdsk_Reboot.bat with this code in it:

echo y > confirm.txt
chkdsk c: /f /x < confirm.txt

Now if you have XP Pro, or other Pro-level OS'es, open gpedit.msc>Computer Configuration>Windows Settings>Scripts>Shutdown, and add that Chkdsk_Reboot.bat as a shutdown script.

Next reboot you will run your chkdsk command.

I am not sure if this will work for XP home since it does not have gpedit.msc. You may be able to create this directory structure and add the batch file there but I am not sure if it will work since Home does not use Group Policy: C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Shutdown

Most people want to STOP chkdsk from running at every boot, but still good info for those looking. Here's a fun add-on, you could change your batch file to one line echo y > conf.txt && (chkdsk c: /f /x < conf.txt & del conf.txt) - Then it will only run chkdsk (and in turn delete the conf.txt) if it successfully creates the conf.txt in the first place. :)
RADCOMPAuthor Commented:
Thanks for the feedback guys, I'm still looking for a way to dynamically grab all logical drives using WMIC or something. I'd prefer not to write to text files just to keep things as clean as possible, tho creating a file then having the script delete it later might not be too bad of a plan.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.