How To Create A Batch File With 2 Commands


Recommended Posts

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.

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

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...