medab1 Posted February 1, 2006 Report Share Posted February 1, 2006 I want to make a batch file to run sfc /scannow & then restart the computer.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.Thank you. Quote Link to post Share on other sites
shanenin Posted February 1, 2006 Report Share Posted February 1, 2006 (edited) are you actually using the "&" inbetween the commands? If so that is probably your problem. Have you tried just putting the two commands on seperate lines. This should run one to completion, then run the second onesfc /scannowshutdown -redit 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 February 1, 2006 by shanenin Quote Link to post Share on other sites
JDoors Posted February 1, 2006 Report Share Posted February 1, 2006 I can't think of a way to prevent the second command from running after the first runs without some kind of user input (i.e., "pause"), unless (and I'm rusty here) some sort of counting/timer is used (if that's still available. Quote Link to post Share on other sites
shanenin Posted February 1, 2006 Report Share Posted February 1, 2006 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.unison -prefer "C:\Documents and Settings\All Users\Documents" -batch sharedunison -prefer "C:\Documents and Settings\liz\My Documents" -batch lizunison -prefer "C:\Documents and Settings\jarrod\My Documents" -batch jarrodunison -prefer "C:\Documents and Settings\brooke\My Documents" -batch brookeunison -prefer "C:\Documents and Settings\wanda\My Documents" -batch wandaunison -prefer "C:\Documents and Settings\shane\My Documents" -batch shaneSHUTDOWN -s -t 01 Quote Link to post Share on other sites
jcl Posted February 1, 2006 Report Share Posted February 1, 2006 (edited) 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.Windows automatically detaches graphical apps from the console. sfc is effectively running as a background process right off the bat (no pun intended).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 February 1, 2006 by jcl Quote Link to post Share on other sites
Torin_Darkflight Posted February 2, 2006 Report Share Posted February 2, 2006 (edited) Try the following:START /WAIT sfc /scannowshutdown -rThis 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 February 2, 2006 by Torin_Darkflight Quote Link to post Share on other sites
jcl Posted February 2, 2006 Report Share Posted February 2, 2006 (edited) D'oh. Okay, I figured it out. The sfc utility is nothing but a front-end to the WFP component of winlogon.exe. The utility activates WFP and exits immediately. This could be very difficult unless the system provides a way to determine whether an WFP scan is in progress.You wouldn't believe what I went through figuring this out :-/ Hooray for overlooking the obvious.. Edited February 2, 2006 by jcl Quote Link to post Share on other sites
medab1 Posted February 2, 2006 Author Report Share Posted February 2, 2006 (edited) I'm working on it.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.exeor 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. EDIT-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 February 2, 2006 by medab1 Quote Link to post Share on other sites
medab1 Posted February 4, 2006 Author Report Share Posted February 4, 2006 The answer was simple.sfc /scanonceOpen RUN.Type in sfc /scanonce & OK.Set up Error-checking & boot time virus scan.Restart Computer.Go to sleep or work.System File Checker automatically runs after Error-checking & a boot time virus scan & Windows restarts.No batch files needed. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.