Scheduled tasks and shutdown.exe

  • Thread starter Thread starter bryan@balfour.me.uk
  • Start date Start date
B

bryan@balfour.me.uk

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.
 
Hi,

A different approach, but may meet your needs?
http://pcworld.about.com/magazine/2206p160id115628.htm

--
All the best,
SG
How to Write a Newsgroup Post:
http://www.elephantboycomputers.com/page2.html#Usenet



<bryan@balfour.me.uk> wrote in message
news:4654c342-336c-4e7c-aec1-4e23a60edb48@v4g2000hsf.googlegroups.com...
> 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.
 
<bryan@balfour.me.uk> wrote in message
news:4654c342-336c-4e7c-aec1-4e23a60edb48@v4g2000hsf.googlegroups.com...
> 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.
 
<bryan@balfour.me.uk> wrote in message
news:45ed81f9-882b-40c3-99b8-7dbf7b494320@p69g2000hsa.googlegroups.com...
>> 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.


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?
 
Hi Bryan,

>>>C:\WINDOWS\system32\shutdown.exe -s -t 15<<<


What happens if you change the time to something like t 30 or 45?
Perhaps for whatever reason, Windows is shutting down to soon even though
your Task hasn't finished. How long does it take for the perl
D:\ExtractPrices.pl to finish?

--
All the best,
SG
How to Write a Newsgroup Post:
http://www.elephantboycomputers.com/page2.html#Usenet



<bryan@balfour.me.uk> wrote in message
news:f831e477-5fed-4332-9e27-cf1ec272ec11@q3g2000hsg.googlegroups.com...
> >
>> 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.
 
> 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).
 
<bryan@balfour.me.uk> wrote in message
news:b34a093f-e8ac-4b28-8b89-4eaae2cbd285@d21g2000prf.googlegroups.com...
>> 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 :>

--
All the best,
SG
How to Write a Newsgroup Post:
http://www.elephantboycomputers.com/page2.html#Usenet



<bryan@balfour.me.uk> wrote in message
news:86b9233a-b18f-4769-8a56-87c896748adf@l16g2000hsf.googlegroups.com...
> 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).
>
>
 
Back
Top