Link to home
Start Free TrialLog in
Avatar of jdera
jdera

asked on

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"?
Avatar of pwrBall
pwrBall
Flag of United States of America image

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
Avatar of jdera
jdera

ASKER

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.
Avatar of Malli Boppe
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 /?
Avatar of jdera

ASKER

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.
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
Avatar of jdera

ASKER

I figured out a solution.  I will have the question deleted.
Please share the solution.
ASKER CERTIFIED SOLUTION
Avatar of jdera
jdera

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
alternatively you can use sleep tool to wait for a specified time.
http://www.computerhope.com/dutil.htm
Avatar of jdera

ASKER

Sleep will not stop it running at a certain period of time.  That will shut everything down, this a server, not a good choice.