Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automated chkdsk /f /r?

Status
Not open for further replies.

Zugdud

IS-IT--Management
Joined
Feb 26, 2003
Messages
158
Location
US
Hi all, Im trying to automate checkdisk with the heavy duty /f /r options rather then /c /i:

I setup scheduled tasks to run 2 commands over the weekend:

This one first:

c:\WINDOWS\system32\chkdsk c: /f /r

Followed by this command 48 hours later:

c:\WINDOWS\system32\shutdown -r -f


The only problem with this is that chkdsk wants you to say y/n to schedualing a restart once it starts running because it needs to tell windows not to start some of the files next time it reboots. Is there a way to pass y using a script or something? Or find out if there is another way to automate this, thanks!

 
To make myself a bit more clear, the

c:\WINDOWS\system32\shutdown -r -f

probably isnt required as from what i understand chkdsk runs before windows starts and then windows starts normally. Im just figure it wouldn't hurt to restart again after 48 hours which would be more then enough time on my client machines =)
 
This is slightly more complicated than you think:

1. Create a registry file.

Copy and paste the below as checkit.reg:

Windows Registry Editor Version 5.00
Code:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
"BootExecute"=hex(7):61,00,75,00,74,00,6f,00,63,00,68,00,65,00,63,00,6b,00,20,00,61,00,75,00,74,00,6f,00,63,00,68,00,6b,00,20,00,2f,00,70,00,20,00,5c,00,3f,00,3f,00,5c,00,43,00,3a,00,00,00,00,00 
**** end copy and paste

2. Create checkit_1.bat to run at say 12:00

regedit /s c:\personal\checkit.reg
exit

3. Create checkit_2.bat to run at say 12:05

c:\windows\system32\shutdown -r -f
exit

Checkdisk will require user intervention without the registry "fix".  It will clear the registry entry after a reboot.

Chkdsk will not run without user intervention of some kind.  This is why the reboot has to be forced if you want chckdsk to run.  This is what the second batch file does.

If you want to reboot your machine 48 hours later you can with another scheduled task as you did above.
 
Perfect, thats just what i was looking for, thanks!
 
Let see if I can make the registry file cleaner:

Code:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager]
"BootExecute"=hex(7):61,00,75,00,74,00,6f,00,63,00,68,00,65,00,63,00,6b,00,20, 00,61,00,75,00,74,00,6f,00,63,00,68,00,6b,00,20,00,2f,00,70,00,20,00,5c,00, 3f,00,3f,00,5c,00,43,00,3a,00,00,00,00,00

Remove the "\" marks, as I had to break these lines somehow.
 
I think you can "pipe" the answer into it. Create a file with c:\yes.txt with just one line in it consisiting of the letter "y" (without quotes) followed by ENTER. Then use:

c:\WINDOWS\system32\chkdsk c: /r < yes.txt

and

c:\WINDOWS\system32\shutdown -r -f < yes.txt

Note: /r implies /f in chkdsk.

Let us know if it worked...

HTH

Gunny
 
Shutdown does not require a user response.

But essentially a pipe will work too as Gunny shows.
 
Although written as a true pipe it would be:

echo Y | chkdsk c: /f
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top