
Adding tasks in Windows Scheduler which should run only on selective months
Dear all.
While adding tasks using windows task scheduler, i am able to specify
certain months on which the task should run.(APR,JUN,SEP,DEC)
(In Windows Scheduler Task, Double click on any task, go to the
schedule tab, choose a monthly schedule and click on select months
button.)
But, while adding the task using WIN32 - API's - NETSCHEDULEADDJOB, i
am unable to setup such a schedule task.
When, i tried to add the task using the following code, the task was
scheduled to run for all months.
Is there any way to acheive what i am trying or i have set my params
to wrong values
<----- Code Starts------------->
'This code add a task to run every 1st day of every month on 4:40 PM
Private Type AT_INFO
dw_JobTime As Long
dw_DaysOfMonth As Long
dw_DaysOfWeek As Byte
dw_Flags As Byte
dw_dummy As Integer
ptr_Command As Long
End Type
Private Declare Function StrToPtr Lib "kernel32" Alias "lstrcpyW"
(ByVal Ptr As Long, Source As Byte) As Long
Private Declare Function NetScheduleJobAdd Lib "netapi32" (Servername
As Byte, PointerToBuffer As AT_INFO, JobInfo As Long) As Long
Private Declare Function NetScheduleJobGetInfo Lib "netapi32"
(Servername As Byte, ByVal JobId As Long, PointerToBuffer As Any) As
Long
Private Declare Function NetAPIBufferFree Lib "netapi32.dll" Alias
"NetApiBufferFree" (ByVal Ptr As Long) As Long
Private Declare Function NetAPIBufferAllocate Lib "netapi32.dll" Alias
"NetApiBufferAllocate" (ByVal ByteCount As Long, Ptr As Long) As Long
Private Sub Command1_Click()
Dim i As Integer
AddJob "server", 60000000, 1, 0, 1, "c:\abc.bat"
End Sub
Function AddJob(sServer As String, _
lTime As Long, _
lDom As Long, _
lDow As Long, _
lFlags As Long, _
sCmd) As Long
Dim aServer() As Byte
Dim lReturn As Long
Dim bDoW As Byte
Dim bFlags As Byte
Dim tInfo As AT_INFO
Dim lJobid As Long
Dim lCmd As Long
Dim aCmd() As Byte
Dim lptr As Long
aServer = sServer & vbNullChar
aCmd = sCmd & vbNullChar
bDoW = lDow
bFlags = lFlags
lReturn = NetAPIBufferAllocate(UBound(aCmd) + 1, lCmd)
lReturn = StrToPtr(lCmd, aCmd(0))
tInfo.dw_JobTime = lTime
tInfo.dw_DaysOfMonth = lDom
tInfo.dw_DaysOfWeek = bDoW
tInfo.dw_Flags = bFlags
tInfo.ptr_Command = lCmd
lReturn = NetScheduleJobAdd(aServer(0), tInfo, lJobid)
lReturn = NetAPIBufferFree(lCmd)
AddJob = True
End Function
<----- Code Ends------------->