Re: How do I run a batch file when a server reboots?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Marten" <absolute88@xxxxxxxxxxx> wrote in message
news:hkrj94db3cp6bv3m4clcvrneifcur8c8fa@xxxxxxxxxx
On Wed, 6 Aug 2008 19:54:47 +0200, "Pegasus \(MVP\)"
<I.can@xxxxxxxxxx> wrote:



It seems you don't want to leave the mark for the ***boot-up***
event but rather for the ***shut-down*** event. Use the Task
Scheduler to invoke a batch file with two commands inside:
- Your "echo" command (probably supplemented with %date%
and %time%)
- shutdown.exe
You should also use the >> redirector so that subsequent
shutdown events do not overwrite the previous ones.


That's a good method, thank you. I forgot to think of calling a batch
file from the scheduler.

My only concern is getting a false positive. By that I mean the first
line (per your suggestion) runs and creates the mark file, but for
what ever reason the Shutdown fails and the server doesn't reboot.
Which has happened. My thinking was if I could put the call to my
batch file in some equivalent of AUTOEXEC.BAT, I could be sure it was
processed during the power up.

The >> redirector is a consideration. I'm mostly concerned with thee
last reboot. But having a bit of history isn't bad. As long as I
remember to trim the file periodically.

for the record, the Shutdown command used is:
C:\WINDOWS\system32\shutdown.exe /r /d p:4:1

Marten

I'm quite aware of the syntax for the shutdown command . . .

Running a command at boot time (the equivalent of Autoexec.bat)
is dead easy: Use the Task Scheduler to run it at boot time.
However - how will you distinguish between a boot after a
scheduled shutdown and a boot caused by a crash?

About trimming the log file: If you schedule a reboot once every
week then you accumulate some 2 kBytes per annum. I would
not call this a huge amount of disk space - it's puny, so why worry?


.



Relevant Pages

  • Re: how to schedule MS degragmenter?
    ... manual way to run Defrag is to click to Start/Control ... you launch the tool via a command line plus ... I have a batch file called "DEFRAG_ALL.BAT" for example, ... Using Task Scheduler To Complete The Process ...
    (microsoft.public.windowsxp.basics)
  • Re: Elegant shutdown method
    ... I generally use the command line Shutdown.exe command with ... I also believe there is a shutdown tool in the Psutils (available ... I schedule with the scheduler so I am not sure about the time. ... I simply setup a batch file on the Main ...
    (microsoft.public.windows.server.active_directory)
  • Re: Task Scheduler permissions problem
    ... It is the AT command that I'm using ... ... this batch file when this batch file is run as a scheduled task in AT. ... assigning the Scheduler service an administrator account to "log on as". ...
    (microsoft.public.windows.server.security)
  • Re: Mass copy of files: how to?
    ... Avoiding "command lines" means that you have to perform the ... suggest a reliable batch file solution based on robocopy.exe. ... (which would be nice when using the Task Scheduler). ... A VERY brief tutorial on how to do this - use a batch file where you redirect the output to log files - for example, even using xcopy right now, you can simply append "output.log 2>&1" and "see" all that you would see if you run the command manually. ...
    (microsoft.public.windows.server.general)
  • Re: How do I make all network computers restart?
    ... Start a Command Prompt. ... create a batch file with this same line. ... If you were a server administrator then I would give ...
    (microsoft.public.windows.server.general)