Adding tasks in Windows Scheduler which should run only on selective months 
Author Message
 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------------->



Wed, 01 Sep 2004 17:04:57 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How to add a task into Windows Task Scheduler from VB

2. Add entry to Windows Task Scheduler from VB

3. Add a task to task scheduler

4. Adding tasks to WIN95/98 Task Scheduler

5. Adding tasks to WIN95/98 Task Scheduler

6. Adding tasks in Win Scheduler programatically

7. Adding tasks in Win Scheduler programatically

8. Adding tasks in Win Scheduler programatically

9. Add Task to Scheduler

10. Add to Task Scheduler?

11. VBA call to Windows Task Scheduler

12. VBA access to Windows Task Scheduler

 

 
Powered by phpBB® Forum Software