I know this is pretty vague, but is there a way to view whether a scheduled task on a different computer (server) is running or not using vb code?
Thanks for any help,
Kevin
Printable View
I know this is pretty vague, but is there a way to view whether a scheduled task on a different computer (server) is running or not using vb code?
Thanks for any help,
Kevin
Check out this page, it has a pretty good example of using the Task Scheduler APIs in VB.
http://www.mvps.org/emorcillo/vb6/grl/index.shtml
HTH
Thanks I'll take a look.
Thanks for the link, but the the example on the url adds and deletes tasks from the schedule tasks on the computer the application is running on.
How can I view whether a task is running or not on a different computer. Thanks for any help... maybe a modification to the program/example on the url listed could help too.
After looking through the code form the link, it appears that while the vb class does add and delete tasks it also has the capabilities to view task status on whatever machine you tell it to look at.
From schedule.cls.......
From Task.cls.......Code:'---------------------------------------------------------------------------------------
' Procedure : TargetComputer
' Purpose : Returns/Sets the target computer where the task will run
'---------------------------------------------------------------------------------------
'
Public Property Get TargetComputer() As String
TargetComputer = StrFromPtrW(m_oScheduler.GetTargetComputer)
End Property
Public Property Let TargetComputer(ByVal Value As String)
m_oScheduler.SetTargetComputer Value
Refresh
End Property
From Test.frmCode:Public Enum JobStatus
' The task is ready to run at its next scheduled time.
TaskReady = SCHED_S_TASK_READY
' The task is currently running.
TaskRunning = SCHED_S_TASK_RUNNING
' The task will not run at the scheduled times because it has been disabled.
TaskDisabled = SCHED_S_TASK_DISABLED
' The task has not yet run.
TaskHashNotRun = SCHED_S_TASK_HAS_NOT_RUN
' There are no more runs scheduled for this task.
TaskNoMoreRuns = SCHED_S_TASK_NO_MORE_RUNS
' One or more of the properties that are needed to run this task on a schedule have not been set.
TaskNotScheduled = SCHED_S_TASK_NOT_SCHEDULED
' The last run of the task was terminated by the user.
TaskTerminated = SCHED_S_TASK_TERMINATED
' Either the task has no triggers or the existing triggers are disabled or not set.
TaskNoValidTriggers = SCHED_S_TASK_NO_VALID_TRIGGERS
End Enum
Public Property Get Status() As JobStatus
Status = m_oTask.GetStatus
End Property
Public Property Get StatusText() As String
Dim lLen As Long
StatusText = String$(256, 0)
lLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS, _
0&, m_oTask.GetStatus, 0&, _
StatusText, Len(StatusText), 0&)
StatusText = Left$(StatusText, lLen)
End Property
After a little more research.....I think all you need to do is find the correct place in frm code to set the TargetComputer property to your target machine.Code:Private Sub lstTasks_Click()
Dim oTrigger As Trigger
With m_oSchedule(lstTasks.ListIndex + 1)
lblInfo(0).Caption = .ApplicationName
lblInfo(1).Caption = .CommandLine
txtComments.Text = .Comment
txtFlags.Text = FlagsText(.Flags)
lblInfo(3).Caption = Format(.LastRunTime, "HH:MM:SS DD-MMM-YYYY")
lblInfo(4).Caption = Format(.NextRunTime, "HH:MM:SS DD-MMM-YYYY")
lblInfo(5).Caption = .Creator
lblInfo(6).Caption = .StatusText
txtSchedule.Text = ""
For Each oTrigger In .Triggers
txtSchedule.Text = txtSchedule.Text & oTrigger.Text & vbNewLine
Next
End With
End Sub
I don't have vb5 or 6 installed on this machine, so I am unable to test this, but I really do think with some slight modifications this sample can made to work for you.Quote:
The ITaskScheduler interface is the most fundamental of the Task Scheduler interfaces. ITaskScheduler lets you add, delete, change, and enumerate tasks, as well as administer tasks on other machines. Obtaining an ITask-Scheduler instance is easy. Simply call CoCreate-Instance, specifying CLSID_CTaskScheduler as the CLSID and IID_ITask--Scheduler as the IID. Here are the ITask-Scheduler interfaces.
SetTargetComputer / GetTargetComputer
Enum
Activate
Delete
NewWorkItem / AddWorkItem
IsOfType