Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I noticed you can only set the day of the month as a positive number 1..31 in the scheduled task GUI on Windows (Windows server 2003).

Is it possible to run a task only on the last day of the month? (This isn't a fixed day number, e.g. in February it could be the 28th or 29th day of the month, and in other months it may be the 30th or 31th.)

Related question, if I set a task to run on the 31th of every month, will it actually run in months with less days? Or will it run on the 1st of the next month in such cases?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Create the task using the schtasks command with the /mo LASTDAY option:

schtasks schedules commands and programs to run periodically or at a specific time. Adds and removes tasks from the schedule, starts and stops tasks on demand, and displays and changes scheduled tasks.

Syntax:

schtasks /create /tn TaskName /tr TaskRun /sc schedule [/mo modifier]
         [/d day] [/m month[,month...] [/i IdleTime] [/st StartTime] 
         [/sd StartDate] [/ed EndDate] [/s computer [/u 
         [domain\]user /p password]] 
         [/ru {[Domain\]User | "System"} [/rp Password]] /? 
share|improve this answer

Set up multiple schedules for the same task. One schedule for months that end on the 31st, one for months that end on the 30th, and another for the 28th. All you have to do is give each task a unique name.

share|improve this answer

Not sure if the GUI supports it natively, but you could get the task to kick off a vbs script or something before hand. Something like:

sub LastDateOfCurMonth() dim lstDateCurMonth, fstDateCurMonth, fstDateNxtMonth fstDateCurMonth="01/" & Month(date) & "/" & Year(Date) fstDateNxtMonth=DateAdd("m",1,fstDateCurMonth) lstDateCurMonth=DateAdd("d",-1,fstDateNxtMonth) wscript.echo "Last Date of Current Month is: " & lstDateCurMonth End Sub

share|improve this answer
    
The script I need to run exit immediately if tomorrow it is the same month as today, so this workaround would be trivial. (I've actually set it up now to just run the script every day; on anything but last day of month it's a no-op.) –  Tobi Jun 25 '09 at 10:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.