Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There was a question a short while ago, Run Program Before Login Screen Appears, where I thought he meant specifically he wanted to run chkdsk on boot based on the picture, but he really wanted to run a different program.

Well, I answered specifically for chkdsk, and I thought some might find my solution to "How do you run chkdsk on every reboot?" interesting.

share|improve this question
Psh, you should make your avatar more interesting. . . – surfasb Jul 26 '11 at 17:05
up vote 6 down vote accepted

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

enter image description here

share|improve this answer
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. :) – Ƭᴇcʜιᴇ007 Jul 26 '11 at 14:23
@techie007 No doubt MOST people would not want to do this unless they are paranoid. The reason I did it was that I had a server with a crappy custom application that would corrupt its SQL database. We had backups just in case, but running chkdsk /f fixed it very time, so I took to scheduling reboots, with my solution running. – KCotreau Jul 26 '11 at 14:39
Yucky.. :( It's hard to fathom that an application could be so bad as to cause an SQL server to corrupt the file system. Again, yucky... :P – Ƭᴇcʜιᴇ007 Jul 26 '11 at 14:44
@techie007 Just its own database thankfully. Eventually, we were able to get the company, who wrote the software just to host it as it was a web app. Off my server was fine with me. – KCotreau Jul 26 '11 at 14:47
Oddly enough, I got a developer who PREFERS to host his database and app specifically because he hates dealing with other IT folks. Yeah, he's a trip. . . – surfasb Jul 26 '11 at 17:04

chkdsk is already set to run on every boot.

Take a look at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager and locate a multi-string (REG_MULTI_SZ) entry called BootExecute. The value "autocheck autochk *" says that chkdsk will run on boot, however you will not see it because it runs on background, searching for disk errors.

If chkdsk detects some disk problem, then you will see the blue screen with full disk scan.


Autocheck option samples, according to here (section: "The Dirty bit vs the Registy "Autochk" entry"):

Sample command              Resulting registry entry 
==============              ========================
Chkdsk C: /F                Autocheck autochk /p \??\C: 
Chkdsk C:\mountpoint /F     Autocheck autochk /p \??\VOLUME{GUID} 
Chkntfs D: E: /X            Autocheck autochk /k:D /k:E * 
Chkntfs G: /C               Autocheck autochk /m \??\G: 
share|improve this answer
I am not sure what it does, but it clearly does not do a full chkdsk /f or chkdsk /r. Even the faster chkdsk /f takes a LOT longer than a typical boot. Autochk must be a very limited version of chkdsk. – KCotreau Jul 26 '11 at 14:22
Here you can get more information: – Diogo Jul 26 '11 at 14:30
It's the full chkdsk, simply compiled as a native API executable. It completes quickly because it looks at the dirty flag. Microsoft does tell you this. – JdeBP Jul 26 '11 at 14:34
I did not realize that autocheck ran chkdsk that way, but doesn't it clear itself out after it runs? You would still need a mechanism to add it back for every reboot to satisfy the question. I will the reason I did this in response to my answer. – KCotreau Jul 26 '11 at 14:37
@JdeBP It is still not doing anything to correct any errors. – KCotreau Jul 26 '11 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .