Scheduled Tasks

dan_
11-14-2005, 05:59 AM
Does anyone know how I can change the "Scheduled Tasks" in Control Panel through code? Even how to shell it would help...

Thanks
Dan_

mcdonnc2004
11-14-2005, 06:22 AM
I found the following article helpful on this subject in the past:

http://www.codeproject.com/shell/ScheduledTaskWizard.asp

dan_
11-14-2005, 06:25 AM
I want to be able to create a scheduled task through code, everything, date, time, program to run.

Dan_

George7a
11-14-2005, 06:25 AM
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
Type AT_INFO
JobTime As Long
DaysOfMonth As Long
DaysOfWeek As Byte
Flags As Byte
dummy As Integer
Command As String
End Type

' Schedule constants
Const JOB_RUN_PERIODICALLY = &H1
Const JOB_NONINTERACTIVE = &H10
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)
Next

Else

' 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
Next
Next
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

also check the following link1 (http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=47254&lngWId=1)

- George

dan_
11-14-2005, 06:27 AM
thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum