Question about performing "chkdsk" from batch at next reboot

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Question about performing "chkdsk" from batch at next reboot

#1 Post by pstein » 20 Feb 2015 00:48

Occasionally I want to perform a well know "chkdsk" command for my Win 7 system at next reboot.
Since I do not always remember immediately the exact syntax I put the following command into a DOS batch script:

chkdsk C: /F /V /R /X >D:\tmp\chkdskreport.log

Mind the /X which means "perform at next reboot"!

When I doubleclick on the batch file it is started BUT from the command prompt the processing stops somehow.
A closer look into the log file reveals: chkdsk is informing the user that the partition C: is locked (=by Win 7 system) andasks if it should be performed at next reboot.

Hmm, why I am asked again? I passed already the /X flag which means YES DO IT at next reboot.
Secondly: How can I view at COMMAND PROMPT window the question (and not only in logfile)?

How can I automatically pass a "y" (without quotes) to the command?

Finally: When I manually enter "y" +<return> at command prompt then yes, the chkdsk is processed at next startup. But no output is not written into file D:\tmp\chkdskreport.log

Why?

Peter

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Question about performing "chkdsk" from batch at next re

#2 Post by ShadowThief » 20 Feb 2015 03:04

You can pass a y to a command like this:

Code: Select all

echo y|chkdisk: /F /V /R /X >D:\tmp\chkdskreport.log

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Question about performing "chkdsk" from batch at next re

#3 Post by foxidrive » 20 Feb 2015 04:49

pstein wrote:I passed already the /X flag which means YES DO IT at next reboot.
Why?


That's not exactly right - it means to dismount the volume.
Say you have a drive H: that you use this switch on, then it will dismount the volume and close any open files
and go ahead.

But the system drive cannot be dismounted - so it has to perform a scheduled chkdsk and asks you for confirmation.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Question about performing "chkdsk" from batch at next re

#4 Post by Squashman » 20 Feb 2015 07:50

pstein wrote:Mind the /X which means "perform at next reboot"!

That is not what the documentation says.

To run chkdsk at boot up you would do this.
Run at Bootup

Running at bootup is often the easiest way to close all open file handles.

Use chkdsk, chkntfs or the FSUTIL dirty commands to set or query the volumes 'dirty' bit so that Windows will run chkdsk when the computer is restarted. This setting is also found in the BootExecute value under HKLM\System\CurrentControlSet\Control\Session Manager

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: Question about performing "chkdsk" from batch at next re

#5 Post by pstein » 10 Mar 2015 01:13

Thank you.
But I still don't understand.

Ok /X is only for dismounting.

But assume I want to chkdsk drive D:\ at next reboot (even if I could dismount it in current session).

How can I achieve this?

Peter

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Question about performing "chkdsk" from batch at next re

#6 Post by ShadowThief » 10 Mar 2015 03:13

Personally, I'd just create a task in Task Scheduler, set it to run "When the computer starts" and then point the "Start a program" option at the script you wrote.

pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Re: Question about performing "chkdsk" from batch at next re

#7 Post by pstein » 10 Mar 2015 03:50

Ok.

Can I create a task from DOS batch script (as cmdline) or do I have to click through multiple menus and dialoges and buttons and settings :-(

OperatorGK
Posts: 66
Joined: 13 Jan 2015 06:55

Re: Question about performing "chkdsk" from batch at next re

#8 Post by OperatorGK » 10 Mar 2015 04:02

Use schtasks /Create /SC ONSTART /TN [name] /TR [your command here] once to do your command at every boot.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Question about performing "chkdsk" from batch at next re

#9 Post by Compo » 10 Mar 2015 07:18

You could also add the request directly to the registry and reboot.

The following example requests a check of your system drive:

Code: Select all

@Echo Off
SetLocal
Set "_Key=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager"
Set "_Val=BootExecute"
Set "_New=autocheck autochk /r \??\%SystemDrive%\0"
For /F "Tokens=2*" %%A In ('Reg Query "%_Key%" /V "%_Val%"') Do Set "_Xst=%%B"
Reg Add "%_Key%" /V "%_Val%" /T REG_MULTI_SZ /D "%_New%%_Xst%" /F>Nul
ShutDown /r /d P:1:1
I haven't included any logging etc. since that is added to the event viewer anyway.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Question about performing "chkdsk" from batch at next re

#10 Post by Samir » 13 Mar 2015 11:27

Another method would be to check for a particular file at startup (that you set up) and if this file exists (or doesn't), run a chkdsk.

For example:

Code: Select all

IF EXIST C:\CHKREPRT.TXT GOTO END
CHKDSK C: > CHKREPRT.TXT
:END
In this example, all you would have to do is delete C:\CHKREPRT.TXT (ideally after reviewing it), and the next time the batch is run (like in the startup or autoexec.bat if win7 has one), the chkdsk will run again.
Last edited by Samir on 13 Mar 2015 11:36, edited 1 time in total.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Question about performing "chkdsk" from batch at next re

#11 Post by Squashman » 13 Mar 2015 11:35

Samir wrote:Another method would be to check for a particular file at startup (that you set up) and if this file exists (or doesn't), run a chkdsk.

Nope. He wants to check the system volume. That has to be done before Windows starts!

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Question about performing "chkdsk" from batch at next re

#12 Post by Samir » 13 Mar 2015 14:06

Squashman wrote:
Samir wrote:Another method would be to check for a particular file at startup (that you set up) and if this file exists (or doesn't), run a chkdsk.

Nope. He wants to check the system volume. That has to be done before Windows starts!
Is there not a way to run commands before 'windows' starts like in 95/98?

Post Reply