?
Solved

How to stop scheduled task after certain time using script

Posted on 2008-01-31
10
Medium Priority
?
3,700 Views
Last Modified: 2012-05-05
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"?
0
Comment
Question by:jdera
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:pwrBall
ID: 20790921
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
 
LVL 20

Author Comment

by:jdera
ID: 20791163
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
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 20794068
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 20

Author Comment

by:jdera
ID: 20796811
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
 
LVL 13

Expert Comment

by:Nick Denny
ID: 20802321
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
 
LVL 20

Author Comment

by:jdera
ID: 21199032
I figured out a solution.  I will have the question deleted.
0
 
LVL 13

Expert Comment

by:Nick Denny
ID: 21199045
Please share the solution.
0
 
LVL 20

Accepted Solution

by:
jdera earned 0 total points
ID: 21201224
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
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 21209854
alternatively you can use sleep tool to wait for a specified time.
http://www.computerhope.com/dutil.htm
0
 
LVL 20

Author Comment

by:jdera
ID: 21210807
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn about cloud computing and its benefits for small business owners.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question