Scheduled tasks and shutdown.exe

  • Thread starter Thread starter bryan
  • Start date Start date
B

bryan

I've a scheduled task that runs a bat file at 23:30 every day. The bat
file contains the following:

perl D:\ExtractPrices.pl
exit

This works fine until I change it to include shutdown.exe so that it
now looks like:

perl D:\ExtractPrices.pl
C:\WINDOWS\system32\shutdown.exe -s -t 15
exit

Now the task executes soon after I boot up the PC and promptly shuts
it down again. Not a lot of use.

Anyone got any ideas why it's doing this?

Surely Windows is unaware of the contents of the bat file until it
comes to execute it at the scheduled time.
 
I've a scheduled task that runs a bat file at 23:30 every day. The bat
file contains the following:

perl D:\ExtractPrices.pl
exit

This works fine until I change it to include shutdown.exe so that it
now looks like:

perl D:\ExtractPrices.pl
C:\WINDOWS\system32\shutdown.exe -s -t 15
exit

Now the task executes soon after I boot up the PC and promptly shuts
it down again. Not a lot of use.

Anyone got any ideas why it's doing this?

Surely Windows is unaware of the contents of the bat file until it
comes to execute it at the scheduled time.

I suspect that perl.exe executes in an independent process
and returns control to the batch file immediately, even while
it is still executing. You can easily check this: Execute the
command "perl D:\ExtractPrices.pl" from a Command Prompt.
Can you enter new commands while the Perl script executes?
There is your answer!

If you cannot modify the behaviour of Perl then you can do this:

@echo off
perl D:\ExtractPrices.pl
:again
ping localhost -n 60 > nul
tasklist | find /i "perl" && goto again
C:\WINDOWS\system32\shutdown.exe -s -t 15
 
I suspect that perl.exe executes in an independent process
and returns control to the batch file immediately, even while
it is still executing. You can easily check this: Execute the
command "perl D:\ExtractPrices.pl" from a Command Prompt.
Can you enter new commands while the Perl script executes?
There is your answer!
No. shutdown.exe doesn't run until the perl program completes.

This still wouldn't explain why this scheduled task, consisting of a
bat file, runs every time windows starts (and consequently shutsdown)
when the shutdown.exe is present in the bat file but only when
scheduled when it isn't. I'm baffled.
 
A different approach, but may meet your needs?http://pcworld.about.com/magazine/2206p160id115628.htm
I've has a quick look at this and probably need to play around with
this approach some more but it seems to be more oriented towards
automating the running of task as part of a user initiated shutdown.
What I'm looking for is a way of running one or more tasks at a set
time every day and then shutting down automatically. I still cannot
understand why the tasks gets run at startup when it contains a
shutdown command but only when scheduled when it doesn't.
 
No. shutdown.exe doesn't run until the perl program completes.

This still wouldn't explain why this scheduled task, consisting of a
bat file, runs every time windows starts (and consequently shutsdown)
when the shutdown.exe is present in the bat file but only when
scheduled when it isn't. I'm baffled.

I am equally baffled by your statement "[It] runs every time windows
starts (and consequently shutsdown) when the shutdown.exe is present
in the bat file but only when scheduled when it isn't."

I read this phrase four times before giving up due to a severe
risk of my brain going into a loop without exit. Can you split
this up so that my simple mind can figure out what you mean?
 
I am equally baffled by your statement "[It] runs every time windows
starts (and consequently shutsdown) when theshutdown.exeis present
in the bat file but only when scheduled when it isn't."

I read this phrase four times before giving up due to a severe
risk of my brain going into a loop without exit. Can you split
this up so that my simple mind can figure out what you mean?

Perhaps you'd find it easier if you read my first post.

Basically, if my scheduled task contains the shutdown.exe line, it
gets executed when windows starts rather than when it is scheduled. In
executing this task at startup, windows then shuts down.
 
Oops, this is soooo embarrassing. Not only have I been wasting my
time, but yours' as well. Here's how it came about.

A while back, long before I realised Windows had a Scheduling
function, I wrote a program to schedule some work at a specified time.
I put the command to execute this program in a bat file follow by the
shutdown.exe line. Having filed this, I then added a shortcut to it to
my Startup folder. This ran happily for a couple of years.

However I recently discovered the Scheduled Task feature of Windows
and thought why not use this instead of my mickey-mouse scheduler
program. So what did I do?
Instead of creating a new bat file, I simply modified the one I had
(1st stupid mistake) and created a Scheduled Task to execute it. I'd
completely forgotten I had a short cut pointing to it in my Startup
folder (2nd stupid mistake). Result: whenever Windows comes up, the
contents of the Startup folder gets executed, the bat file is run and
windows shuts down.

What can I say apart from apologising to all who spent time on this
(and reach for another slice of humble pie).
 
I am equally baffled by your statement "[It] runs every time windows
starts (and consequently shutsdown) when theshutdown.exeis present
in the bat file but only when scheduled when it isn't."

I read this phrase four times before giving up due to a severe
risk of my brain going into a loop without exit. Can you split
this up so that my simple mind can figure out what you mean?

Perhaps you'd find it easier if you read my first post.

Basically, if my scheduled task contains the shutdown.exe line, it
gets executed when windows starts rather than when it is scheduled. In
executing this task at startup, windows then shuts down.

Reading your subsequent post I now know that is problem
is of your own making.
 
Hi,

No apology needed my friend. We all look over things sometimes, but we also
learn from our mistakes.The end result is you got it working right? well
that's what we were after. BTW, pumpkin pie sounds better :>
 
Back
Top