Hi Experts,
     how can i schedule a task from VB6?. ie., how can i access the Windows Task Scheduler from Visual Basic 6.0. Bcoz i want to schedule an application that should start whenever i logged in. Is there any material on NET?.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here's an example of scheduling a Task....


Option Explicit
' Schedule api's
Declare Function NetScheduleJobAdd Lib "netapi32.dll" _
(ByVal Servername As String, Buffer As Any, Jobid As Long) As Long

' Schedule structure
    JobTime     As Long
    DaysOfMonth As Long
    DaysOfWeek  As Byte
    Flags       As Byte
    dummy       As Integer
    Command     As String
End Type

' Schedule constants
Const NERR_Success = 0

Private Sub Command1_Click()
    Dim lngWin32apiResultCode As Long
    Dim strComputerName As String
    Dim lngJobID As Long
    Dim udtAtInfo As AT_INFO
    ' Convert the computer name to unicode
    strComputerName = StrConv(Text1.Text, vbUnicode)
    ' Setup the tasks parameters
    SetStructValue udtAtInfo
    ' Schedule the task
    lngWin32apiResultCode = NetScheduleJobAdd(strComputerName, udtAtInfo, lngJobID)
    ' Check if the task was scheduled
    If lngWin32apiResultCode = NERR_Success Then
        MsgBox "Task" & lngJobID & " has been scheduled."
    End If
End Sub
Private Sub SetStructValue(udtAtInfo As AT_INFO)
    Dim strTime As String
    Dim strDate() As String
    Dim vntWeek() As Variant
    Dim intCounter As Integer
    Dim intWeekCounter As Integer
    vntWeek = Array("M", "T", "W", "TH", "F", "S", "SU")
    With udtAtInfo
        ' Change the format of the time
        strTime = Format(Text2.Text, "hh:mm")
        ' Change the time to one used by the api
        .JobTime = (Hour(strTime) * 3600 + Minute(strTime) * 60) * 1000
        ' Set the Date parameters
        If Val(Text3.Text) > 0 Then
            ' Set the task to run on specific days of the month i.e. 9th & 22nd of the month
            strDate = Split(Text3.Text, ",")
            For intCounter = 0 To UBound(strDate)
                .DaysOfMonth = .DaysOfMonth + 2 ^ (strDate(intCounter) - 1)
            ' Set the task to run on sepecific days of the week i.e. Monday & Thursday
            strDate = Split(Text3.Text, ",")
            For intCounter = 0 To UBound(strDate)
                For intWeekCounter = 0 To UBound(vntWeek)
                    If UCase(strDate(intCounter)) = vntWeek(intWeekCounter) Then
                        .DaysOfWeek = .DaysOfWeek + 2 ^ intWeekCounter
                        Exit For
                    End If
        End If
        ' Set the interactive property
        If Check1.Value = vbUnchecked Then
            .Flags = .Flags Or JOB_NONINTERACTIVE
        End If
        ' Set to run periodically
        If Option2.Value = True Then
            .Flags = .Flags Or JOB_RUN_PERIODICALLY
        End If
        ' Set the command to run
        .Command = StrConv(Text4.Text, vbUnicode)
    End With
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can also use the AT scheduler. Go the command line and type AT /? for more details.

Use the Shell command to actually run your AT command.
RagavanSPAuthor Commented:
ThanQ for all,
     Sorry or the delay. i went for a vocation.

RagavanSPAuthor Commented:
or -- for

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.