How To Create A Batch File With 2 Commands
Posted 01 February 2006 - 05:59 AM
I use XP Home SP2.
I made one with sfc /scannow & shutdown -r but it restarts after sfc /scannow is just starting to run.
I need sfc /scannow to finish & then for the restart command to kick in.
The purpose is to let sfc /scannow to run & the computer to restart & run Error Checking & a boot time Avast scan.
I can set up the Avast & Error checking seperate from the .bat file.
They will run when the computer restarts.
Any help will be appreciated.
Posted 01 February 2006 - 09:51 AM
sfc /scannow shutdown -r
edit added later//
I think I gave you bad information. I based my answer on using a bash shell(linux). In bash if you use the "&" inbetween two commands it will execute the second before the first finishes. I just tested this using a windows command line. Using the "&" seems to complete the first command until finsihed, then execute the second command. You would think it would finish the sfc command before executing the shutdown command. I would still try it on two seperate lines, but my hunch is it will not help.
Edited by shanenin, 01 February 2006 - 10:55 AM.
Posted 01 February 2006 - 02:06 PM
Posted 01 February 2006 - 05:45 PM
unison -prefer "C:\Documents and Settings\All Users\Documents" -batch shared unison -prefer "C:\Documents and Settings\liz\My Documents" -batch liz unison -prefer "C:\Documents and Settings\jarrod\My Documents" -batch jarrod unison -prefer "C:\Documents and Settings\brooke\My Documents" -batch brooke unison -prefer "C:\Documents and Settings\wanda\My Documents" -batch wanda unison -prefer "C:\Documents and Settings\shane\My Documents" -batch shane SHUTDOWN -s -t 01
Posted 01 February 2006 - 06:17 PM
Windows automatically detaches graphical apps from the console. sfc is effectively running as a background process right off the bat (no pun intended).
I use this script on my home computer to backup all of my familys documents, then it shuts down the computer. It runs one command at a time. After each command is finished, it then goes to the next command. That is the default behavior for any scripting language.
AFAICT there's no easy way to wait for an arbitrary process to terminate from a batch file. I fiddled with WSH (Windows Scripting Host) last night and couldn't find an obvious way to wait with it either. WSH is supposed to let you wait so you can capture the exit status of a process but it didn't work with sfc. Go figure.
Edited by jcl, 01 February 2006 - 06:46 PM.
Posted 01 February 2006 - 11:03 PM
START /WAIT sfc /scannow
This should force the batch script to wait until SFC is done before continuing to the shutdown command. If that doesn't work, try putting quotes around sfc /scannow.
Edited by Torin_Darkflight, 01 February 2006 - 11:10 PM.
Posted 02 February 2006 - 01:50 AM
You wouldn't believe what I went through figuring this out :-/ Hooray for overlooking the obvious.
Edited by jcl, 02 February 2006 - 02:12 AM.
Posted 02 February 2006 - 08:19 AM
Thanks for the input.
I'll get back here after a while to let you know if I get this to work or not.
I was wondering if the shutdown -r points to an .exe file in Windows?
If so,maybe one could use
start /wait sfc /scannow & whatever.exe
or something like that?
I will now proceed to test the suggestions already posted.
It may be another day or so before I get back here.
Thank you all.
Maybe I could make 2 batch files.
Put the shutdown -r in one.
Run sfc /scannow & then call up the second (shutdown -r file) from the first.???
I'll try it after I test other options.
Edited by medab1, 02 February 2006 - 08:38 AM.
Posted 03 February 2006 - 07:34 PM
Type in sfc /scanonce & OK.
Set up Error-checking & boot time virus scan.
Go to sleep or work.
System File Checker automatically runs after Error-checking & a boot time virus scan & Windows restarts.
No batch files needed.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users