-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: hereiam_always
Message 1 in Discussion

Hi All here is some i found for schedulling a job from Visual Basic 
-----------------------------------------------------  
Option Explicit<o:p></o:p> 
' Schedule api's<o:p></o:p> 
Declare Function NetScheduleJobAdd Lib "netapi32.dll" _<o:p></o:p> 
(ByVal Servername As String, Buffer As Any, Jobid As Long) As Long<o:p></o:p> 
<o:p> </o:p> 
' Schedule structure<o:p></o:p> 
Type AT_INFO<o:p></o:p> 
    JobTime     As Long<o:p></o:p> 
    DaysOfMonth As Long<o:p></o:p> 
    DaysOfWeek  As Byte<o:p></o:p> 
    Flags       As Byte<o:p></o:p> 
    dummy       As Integer<o:p></o:p> 
    Command     As String<o:p></o:p> 
End Type<o:p></o:p> 
<o:p> </o:p> 
' Schedule constants<o:p></o:p> 
Const JOB_RUN_PERIODICALLY = &H1<o:p></o:p> 
Const JOB_NONINTERACTIVE = &H10<o:p></o:p> 
Const NERR_Success = 0<o:p></o:p> 
<o:p> </o:p> 
Private Sub Command1_Click()<o:p></o:p> 
    Dim lngWin32apiResultCode As Long<o:p></o:p> 
    Dim strComputerName As String<o:p></o:p> 
    Dim lngJobID As Long<o:p></o:p> 
    Dim udtAtInfo As AT_INFO<o:p></o:p> 
    <o:p></o:p> 
    ' Convert the computer name to unicode<o:p></o:p> 
    strComputerName = StrConv(Text1.Text, vbUnicode)<o:p></o:p> 
    <o:p></o:p> 
    ' Setup the tasks parameters<o:p></o:p> 
    SetStructValue udtAtInfo<o:p></o:p> 
    <o:p></o:p> 
    ' Schedule the task<o:p></o:p> 
    lngWin32apiResultCode = NetScheduleJobAdd(strComputerName, udtAtInfo, 
lngJobID)<o:p></o:p> 
    <o:p></o:p> 
    ' Check if the task was scheduled<o:p></o:p> 
    If lngWin32apiResultCode = NERR_Success Then<o:p></o:p> 
        MsgBox "Task" & lngJobID & " has been scheduled."<o:p></o:p> 
    End If<o:p></o:p> 
    <o:p></o:p> 
End Sub<o:p></o:p> 
Private Sub SetStructValue(udtAtInfo As AT_INFO)<o:p></o:p> 
    Dim strTime As String<o:p></o:p> 
    Dim strDate() As String<o:p></o:p> 
    Dim vntWeek() As Variant<o:p></o:p> 
    Dim intCounter As Integer<o:p></o:p> 
    Dim intWeekCounter As Integer<o:p></o:p> 
    <o:p></o:p> 
    vntWeek = Array("M", "T", "W", "TH", "F", "S", "SU")<o:p></o:p> 
    <o:p></o:p> 
    With udtAtInfo<o:p></o:p> 
        <o:p></o:p> 
        ' Change the format of the time<o:p></o:p> 
        strTime = Format(Text2.Text, "hh:mm")<o:p></o:p> 
        <o:p></o:p> 
        ' Change the time to one used by the api<o:p></o:p> 
        .JobTime = (Hour(strTime) * 3600 + Minute(strTime) * 60) * 
1000<o:p></o:p> 
        <o:p></o:p> 
        ' Set the Date parameters<o:p></o:p> 
        If Val(Text3.Text) > 0 Then<o:p></o:p> 
            <o:p></o:p> 
            ' Set the task to run on specific days of the month i.e. 9th & 22nd 
of the month<o:p></o:p> 
            strDate = <st1:place w:st="on"><st1:City 
w:st="on">Split</st1:City></st1:place>(Text3.Text, ",")<o:p></o:p> 
            For intCounter = 0 To UBound(strDate)<o:p></o:p> 
                .DaysOfMonth = .DaysOfMonth + 2 ^ (strDate(intCounter) - 
1)<o:p></o:p> 
            Next<o:p></o:p> 
        <o:p></o:p> 
        Else<o:p></o:p> 
            <o:p></o:p> 
            ' Set the task to run on sepecific days of the week i.e. Monday & 
Thursday<o:p></o:p> 
            strDate = <st1:place w:st="on"><st1:City 
w:st="on">Split</st1:City></st1:place>(Text3.Text, ",")<o:p></o:p> 
            For intCounter = 0 To UBound(strDate)<o:p></o:p> 
                For intWeekCounter = 0 To UBound(vntWeek)<o:p></o:p> 
                    If UCase(strDate(intCounter)) = vntWeek(intWeekCounter) 
Then<o:p></o:p> 
                        .DaysOfWeek = .DaysOfWeek + 2 ^ 
intWeekCounter<o:p></o:p> 
                        Exit For<o:p></o:p> 
                    End If<o:p></o:p> 
                Next<o:p></o:p> 
            Next<o:p></o:p> 
        End If<o:p></o:p> 
        <o:p></o:p> 
        ' Set the interactive property<o:p></o:p> 
        If Check1.Value = vbUnchecked Then<o:p></o:p> 
            .Flags = .Flags Or JOB_NONINTERACTIVE<o:p></o:p> 
        End If<o:p></o:p> 
        <o:p></o:p> 
        ' Set to run periodically<o:p></o:p> 
        If Option2.Value = True Then<o:p></o:p> 
            .Flags = .Flags Or JOB_RUN_PERIODICALLY<o:p></o:p> 
        End If<o:p></o:p> 
        <o:p></o:p> 
        ' Set the command to run<o:p></o:p> 
        .Command = StrConv(Text4.Text, vbUnicode)<o:p></o:p> 
    End With<o:p></o:p> 
End Sub<o:p></o:p>

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to