How to stop scheduled task after certain time using script

With Windows 2003 server, how do you stop a scheduled task after certain time using script, using the property of "Stop the task if it runs for X hours and Y minutes"?
LVL 20
jderaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pwrBallCommented:
Try this:
http://www.beyondlogic.org/solutions/processutil/processutil.htm

Just have a follow-up scheduled task to end X hours and X minutes after the initial scheduled task
0
jderaAuthor Commented:
As mentioned, I would prefer to have some way via a switch to do it within the schtask script.  Plus what you provided is only supported using 2000/NT/XP, not 2003.
0
Malli BoppeCommented:
You need to use schtasks command which is in built in windows 2003 to  automatcially start or stop the scheduled task.


SCHTASKS /parameter [arguments]

Description:
    Enables an administrator to create, delete, query, change,
    end scheduled tasks on a local or remote system. Replaces

Parameter List:
    /Create         Creates a new scheduled task.

    /Delete         Deletes the scheduled task(s).

    /Query          Displays all scheduled tasks.

    /Change         Changes the properties of scheduled task.

    /Run            Runs the scheduled task immediately.

    /End            Stops the currently running scheduled task

    /?              Displays this help/usage.

Examples:
    SCHTASKS
    SCHTASKS /?
    SCHTASKS /Run /?
    SCHTASKS /End /?
    SCHTASKS /Create /?
    SCHTASKS /Delete /?
    SCHTASKS /Query  /?
    SCHTASKS /Change /?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

jderaAuthor Commented:
mboppe:

What you provided was the help from the command in DOS, but where in the arguments you provided can you assign a value to how long it will run?  As I mentioned above, the task will run for X hours and Y minutes.  This parameter I am looking for is the same parameter that is built into the GUI of the task scheduler for a particular schedule.
0
Nick DennyCommented:
It seems that you can only stop a task at either a specified time or after so many minutes, only on tasks that are on a MINUTE or HOURLY schedule, as seen on the  /et (end time) and /du (duration) switches.
http://technet2.microsoft.com/windowsserver/en/library/1d284efa-9d11-46c2-a8ef-87b297c68d171033.mspx?mfr=true
0
jderaAuthor Commented:
I figured out a solution.  I will have the question deleted.
0
Nick DennyCommented:
Please share the solution.
0
jderaAuthor Commented:
Sure, if you are truly that interested.

@echo off
start /b "" "c:\tools\FTP Batchfile.bat"
ping localhost -n 300 > nul
c:\tools\tlist | find /i "ftp" && kill ftp

This batch file will run two separate threads. One is the FTP
transfer, the other a wait loop. After about 300 seconds,
the wait loop kills ftp if it still active.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Malli BoppeCommented:
alternatively you can use sleep tool to wait for a specified time.
http://www.computerhope.com/dutil.htm
0
jderaAuthor Commented:
Sleep will not stop it running at a certain period of time.  That will shut everything down, this a server, not a good choice.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.