Jump to content


Photo

How To Create A Batch File With 2 Commands


  • Please log in to reply
8 replies to this topic

#1 medab1

medab1

    Full Member

  • Members
  • PipPip
  • 99 posts

Posted 01 February 2006 - 05:59 AM

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.

#2 shanenin

shanenin

    UberTechie

  • Moderator
  • 3782 posts
  • Location:rochester , MN USA
  • Operating System:Ubuntu 8.04

Posted 01 February 2006 - 09:51 AM

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, 01 February 2006 - 10:55 AM.


#3 JDoors

JDoors

    UberTechie

  • Members
  • PipPipPipPipPipPip
  • 3561 posts

Posted 01 February 2006 - 02:06 PM

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.

#4 shanenin

shanenin

    UberTechie

  • Moderator
  • 3782 posts
  • Location:rochester , MN USA
  • Operating System:Ubuntu 8.04

Posted 01 February 2006 - 05:45 PM

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


#5 jcl

jcl

    UberTechie

  • Linux Experts
  • 1304 posts
  • Location:The Internet
  • Operating System:Arch

Posted 01 February 2006 - 06:17 PM

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, 01 February 2006 - 06:46 PM.


#6 Torin_Darkflight

Torin_Darkflight

    Full Member

  • Members
  • PipPip
  • 69 posts
  • Location:USA
  • Operating System:Windows XP Professional

Posted 01 February 2006 - 11:03 PM

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, 01 February 2006 - 11:10 PM.


#7 jcl

jcl

    UberTechie

  • Linux Experts
  • 1304 posts
  • Location:The Internet
  • Operating System:Arch

Posted 02 February 2006 - 01:50 AM

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, 02 February 2006 - 02:12 AM.


#8 medab1

medab1

    Full Member

  • Members
  • PipPip
  • 99 posts

Posted 02 February 2006 - 08:19 AM

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, 02 February 2006 - 08:38 AM.


#9 medab1

medab1

    Full Member

  • Members
  • PipPip
  • 99 posts

Posted 03 February 2006 - 07:34 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users