How do you run chkdsk on every reboot?

8,721

Solution 1

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

Solution 2

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.

Edit:

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:
8,721

Related videos on Youtube

hicklypups
Author by

hicklypups

Updated on September 18, 2022

Comments

  • hicklypups
    hicklypups almost 2 years

    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.

    • surfasb
      surfasb almost 13 years
      Psh, you should make your avatar more interesting. . .
  • Ƭᴇcʜιᴇ007
    Ƭᴇcʜιᴇ007 almost 13 years
    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. :)
  • Diogo
    Diogo almost 13 years
    Here you can get more information: support.microsoft.com/kb/831426/en-us
  • JdeBP
    JdeBP almost 13 years
    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.
  • hicklypups
    hicklypups almost 13 years
    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.
  • hicklypups
    hicklypups almost 13 years
    @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.
  • Ƭᴇcʜιᴇ007
    Ƭᴇcʜιᴇ007 almost 13 years
    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
  • hicklypups
    hicklypups almost 13 years
    @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.
  • hicklypups
    hicklypups almost 13 years
    @JdeBP It is still not doing anything to correct any errors.
  • surfasb
    surfasb almost 13 years
    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. . .