Sponsored By

Sign in to follow this  
Followers 0
medab1

How To Create A Batch File With 2 Commands

9 posts in this topic

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.

Share this post


Link to post
Share on other sites

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 one

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 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

Share this post


Link to post
Share on other sites
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 by jcl

Share this post


Link to post
Share on other sites

Try the following:

START /WAIT sfc /scannow

shutdown -r

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

Share this post


Link to post
Share on other sites

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 by jcl

Share this post


Link to post
Share on other sites

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.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. :)

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 by medab1

Share this post


Link to post
Share on other sites

The answer was simple.

sfc /scanonce

Open 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. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0