Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a daily job from the Windows Scheduler

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I have read a number of threads concerning the Scheduler (including this which is quite detailed: but I cannot see how to code my program to add a scheduled task to run at a specific time daily.

Do I have to setup a task for each day of the week with JOB_RUN_PERIODICALLY, or is there a simpler way?

Also, I notice that in a Scheduled Task's settings, it is possible to stop the task if it runs for a certain period. Can this be programmed as well?

Any help would be appreciated.
 
Why do you have to use the Scheduled task ?

Why not make a program ( to run on a desktop / server ) which can be on 24/7 ( so you can run at your specified time ) , Hide it in the system tray , and chose what time you run it using a SleepAPI timer ? (rather than loops which cain your CPU )

Hope im not missing the point ?

Chris
 
royalcheese, previously we ran the program from the system tray. However, we found that occasionally customers 'accidently' closed/deleted the program. So we are looking at running the program from the scheduler.

The program transmits data overnight by FTP to a remote server. The option to stop the program after a certain period would be useful to disconnect the modem in the case of a comms error.

 
I have made the very same program , you can disable acciental termination by changing the ControlBox option on the form to "False" which takes out the X to close forms, so only a alt-crt-del will do.

and add to start up so it starts for them, hot watching folders is also a good thing to do , so when a file gets in the folder , it gets ftped then rather than at 2 in the morning.

Or if you can run on a seperate pc just a basic desktop wiht a network connection, so users cant shut down.

Hope this helps
 
royalcheese, thanks for the information.

There was a second reason to use the scheduler. This concerns the FTP and modem. We found that occasionally (for some reason) the transmission may 'hang', resulting in the modem not closing and a large telephone bill.

The FTP should take no more than ten minutes. Our plan was to schedule the transmission to start for example at 1am, then a second program to start at 1.30am which would check whether the transmission program was still running and if so, kill it.

I suppose both programs running from the system tray might work just as well.

 
croydon, make sure that you include the changes advised by davidlandy at the end of the thread you reference. This should then mean you can set up repeating daily tasks
 
I have got this working but only by setting up seven tasks, one for each day.

Unless I am missing something, there does not seem to be a way of programmatically creating one task that will repeat each day.
 
I can't test it - have no VB here - but I wonder if you can just set DaysOfWeek to 128, so all bits for all days are set?
 
Actually, looking at my code in thread222-794484 I vaguely recall updating it slightly at a later date to deal with exactly this problem. Can't find the relevant thread at the moment (indeed I'm not completely certain I posted it), so I'll have to trawl through my code library when I get home tonight to see if I can find it.
 
A check of my library shows that the only change I made was to incorporate davidlandy's modification ... which means that it is probably something to do with the way you are calling it. Here's how I'd set up a task to run every weekday:


vbScheduleJob "notepad", DateAdd("n", 1, Now), JOB_RUN_PERIODICALLY, Monday + Tuesday + Wednesday + Thursday + Friday
 
Look at the AT command from the command line. It allows you to schedule tasks programmatically.

The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
[ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername Specifies a remote computer. Commands are scheduled on the
local computer if this parameter is omitted.
id Is an identification number assigned to a scheduled
command.
/delete Cancels a scheduled command. If id is omitted, all the
scheduled commands on the computer are canceled.
/yes Used with cancel all jobs command when no further
confirmation is desired.
time Specifies the time when command is to run.
/interactive Allows the job to interact with the desktop of the user
who is logged on at the time the job runs.
/every:date[,...] Runs the command on each specified day(s) of the week or
month. If date is omitted, the current day of the month
is assumed.
/next:date[,...] Runs the specified command on the next occurrence of the
day (for example, next Thursday). If date is omitted, the
current day of the month is assumed.
"command" Is the Windows NT command, or batch program to be run.

The GUI offers more options, like the EVERY choice, but this should show you how to get what you want.

You can also use the START command with the /WAIT option to create a batch file, which you can then schedule.

Check out AT /? and START /? from a command prompt.

-David
2006 Microsoft Most Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
NetScheduleJobAdd, which is what we are talking about, is the AT command ...
 
I've been testing this and the best solution I have found is that suggested by tsh73 where the 'days of week' are set to 127 (all bits).

This creates one schedule that runs the program each day of the week. This is not daily in the way that a manual 'Daily' is setup, rather it runs weekly for each day of the week.

This is probably the best I can get and will do the job, so thanks to everyone for their suggestions.

 
>'days of week' are set to 127

Which is simply the same as setting it to Monday + Tuesday + Wednesday + Thursday + Friday + Saturday + Sunday

> This is not daily in the way that a manual 'Daily' is setup

Well, it is if by manual you mean using the AT command, since it is the AT command that NetScheduleJobAdd implements as already mentioned (try running

[tt]at 20:05 /every:monday,tuesday,wednesday,thursday,friday,saturday,sunday "notepad.exe"[/tt]

at a command prompt and then examining 'Scheduled Tasks' to see how it looks)

If, on the other hand, you use the Task Scheduler ('Scheduled Tasks'), then this is actually a different tool to the AT command (and thus NetScheduleJobAdd), which is why the scheduling in submitted AT (and by NetScheduleJobAdd) commands is greyed out when you examine the properties in 'Scheduled Tasks'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top