Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ok, so there was an error, I want the batch file to continue. 1

Status
Not open for further replies.

RhondaJC

Technical User
May 3, 2002
19
0
0
US
I have created a batch file to remotely restart all the PCs on our network at 11:50 pm each night. I created the batch file, then set up a Task in Task Scheduler to accomplish this using shutdown.exe from the Win2K Resource Kit.

The only problem I'm running into, is if a user has powered off their PC, then Windows returns an error screen, and my batch file stops.

What can I put in the batch file that says, "That's ok, I didn't really need to reboot that PC, please move to the next line in the batch file and continue."

:-D
Rhonda
 
I have no experience with shutdown.exe, but looking at your problem generically: are you saying that a batch file that consists of lines like

shutdown.exe [Machine1]
shutdown.exe [Machine2]
shutdown.exe [Machine3]

hangs when it fails on machine1?

Or is your batch file like

call shutM1.bat
call shutM2.bat
call shutM3.bat

In the latter case, at least I see why everything stops for you.
 
Hmm. Don't know how many PCs we're talking about here, but what if instead of one script to reboot all the PCs, you had 20 scripts, each designed to shut down a particular PC? That way one PC could only stop one of the scripts, not the rest.
 
Chris,

She said she was doing a batch file, in which case you have said the exact opposite of what I did, and I stand by my first post. Batch statements calling batch statements wait for control to return. Batch commands to run batch files loses control. It sounds she has batches calling batches.

But if she really meant a nonbatch script, you may be right.

At any rate, it's nice to listen to ourselves breathe. I wonder why people never respond back after someone like you and I spent our personal time to try to assist :(
 
Here's what my batch file says:

Code:
"C:\WINNT\system32\CMD.EXE /K"
shutdown \\machine2 /c /r
shutdown \\machine4 /c /r
shutdown \\machine5 /c /r
shutdown \\machine6 /c /r
shutdown \\machine7 /c /r
shutdown \\machine10 /c /r
shutdown \\machine11 /c /r
shutdown \\machine12 /c /r
shutdown \\machine14 /c /r
shutdown \\machine17 /c /r
shutdown \\machine18 /c /r
shutdown \\machine19 /c /r
shutdown \\machine21 /c /r
shutdown \\machine22 /c /r
shutdown \\machine25 /c /r
shutdown \\machine27 /c /r
shutdown \\machine28 /c /r
shutdown \\machine29 /c /r
shutdown \\machine30 /c /r
shutdown \\machine31 /c /r
shutdown \\machine32 /c /r
shutdown \\machine34 /c /r
shutdown \\machine38 /c /r
shutdown \\machine42 /c /r
shutdown \\machine43 /c /r
shutdown \\machine44 /c /r
shutdown \\machine45 /c /r
shutdown \\machine46 /c /r
shutdown \\machine47 /c /r
shutdown \\machine50 /c /r
shutdown \\machine57 /c /r
shutdown \\machine58 /c /r
shutdown \\machine59 /c /r
shutdown \\machine60 /c /r
shutdown \\machine61 /c /r
shutdown \\machine62 /c /r
shutdown \\machine101 /c /r
shutdown \\machine37 /c /r
exit

The batch will stop, if Windows returns an error message on any of the machines. The error window states that it could not establish a connection. It will then stop the batch file. I'd like to add something to the batch, telling it to click "ok" on any error screens, and continue.

I have this set up as one task, running under my Domain Admin userid. To set up separate tasks, would require me to make changes to all those tasks every time I'm required to change my password. Using the Local Admin userID is not an option. (Security reasons within our company)

Any help is greatly appreciated. I apologize for not checking this forum over the weekend.

Rhonda
 
Have you tried the /y switch for shutdown.exe? It causes the batch to resume if a "question" is posed, although the error you are getting may not not qualify.
 
Can you use the 'If (not) errorlevel' conditional following each command?
 
Just to make sure I understand, my syntax should be:

shutdown \\machine37 /c /y /r

Is that what you mean?
 
Wolf,

I'm not familiar with the "'If (not) errorlevel' conditional following each command" you mentioned. Could you please give me more information?

Rhonda

 
Look in win2k help under batch commands. Commands which are not successful should set Errorlevel to a non-zero value (but I'm not sure if they all do - you'd need to check it out manually first).

Eg, from bit of your file:-

shutdown \\machine2 /c /r
If not errorlevel 0 goto machine4
:machine4
shutdown \\machine4 /c /r
If not errorlevel 0 goto machine5
:machine5
shutdown \\machine5 /c /r
If not errorlevel 0 goto machine6
:machine6
shutdown \\machine6 /c /r

So, processing should either continue to next machine (no error) or get sent there (is error). But as I said, you need to test that shutdown returns an errorlevel.
 
I like your idea better than mine, Wolluf.
 
My first try will be to add the \y on each shutdown line. If that doesn't work tonight, I'll try Wolluf's suggestion.

I'll let you know how it goes, and vote the suggestion that worked.

Thanks again!
Rhonda [pc2]
 
errorlevel is not of use here. It only matters when the batch file is still executing - not when execution has stopped.
 
I tried adding the /y to each line in the order we discussed:

Example:
shutdown \\machine37 /c /y /r

It still stopped with the same error message:
Window Title is "Error" with no mention of the program. Although from the verbage, I tend to think it's a shutdown.exe error message. Would changing the order of the switches make any difference? ie- /y /c /r

After the latest post, I'm unclear on whether to try Wolluf's suggestion.

More opinions anyone?

Thanks,
Rhonda
 
Rhonda,

You've got nothing to lose trying it - as I said I'm not sure if shutdown populates errorlevel (but you could test it - just run a batch file with single or double entry like I suggested using (a) non-existent machine name(s) and see if it carries on or not - I haven't got the shutdown program or I'd have tried myself).
 
No, I don't think the order the switches are listed makes any difference. It was kind of a longshot, as the /y switch just auto-answers "yes" to any following questions.
 
PS. I've just downloaded a version of shutdown (don't know if its right one) and tried my batch file run from command prompt with 2 entries - it completed both - error displayed in command window - so might be worth a try.
 
Wolluf,

You're right. Nothing to lose by trying it. I'm changing the batch (not a big deal), and we'll see how it goes. I will check it tomorrow to let you know.

Thanks,
Rhonda
 
download the shutdown.exe from XP and try it using something like this:
shutdown -m \\machine1 -r -t 1 -c -y
shutdown -m \\machine2 -r -t 1 -c -y
shutdown -m \\machine3 -r -t 1 -c -y

go to ftp.griceonline.com Vince Grice
vgrice@hotmail.com
MCSE Win2K, NT; MCSA; MCP+I
favicon.ico

I not only use all the brains I have, but all I can borrow.
- Woodrow Wilson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top