Question about performing "chkdsk" from batch at next reboot
Moderator: DosItHelp
Question about performing "chkdsk" from batch at next reboot
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
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
-
- Expert
- Posts: 1160
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Question about performing "chkdsk" from batch at next re
You can pass a y to a command like this:
Code: Select all
echo y|chkdisk: /F /V /R /X >D:\tmp\chkdskreport.log
Re: Question about performing "chkdsk" from batch at next re
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.
Re: Question about performing "chkdsk" from batch at next re
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
Re: Question about performing "chkdsk" from batch at next re
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
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
-
- Expert
- Posts: 1160
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Question about performing "chkdsk" from batch at next re
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.
Re: Question about performing "chkdsk" from batch at next re
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
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
-
- Posts: 66
- Joined: 13 Jan 2015 06:55
Re: Question about performing "chkdsk" from batch at next re
Use schtasks /Create /SC ONSTART /TN [name] /TR [your command here] once to do your command at every boot.
Re: Question about performing "chkdsk" from batch at next re
You could also add the request directly to the registry and reboot.
The following example requests a check of your system drive:I haven't included any logging etc. since that is added to the event viewer anyway.
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
Re: Question about performing "chkdsk" from batch at next re
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: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.
For example:
Code: Select all
IF EXIST C:\CHKREPRT.TXT GOTO END
CHKDSK C: > CHKREPRT.TXT
:END
Last edited by Samir on 13 Mar 2015 11:36, edited 1 time in total.
Re: Question about performing "chkdsk" from batch at next re
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!
Re: Question about performing "chkdsk" from batch at next re
Is there not a way to run commands before 'windows' starts like in 95/98?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!