This VBScript example shows how to use the "ShowRunningTasks" function to find out what tasks are currently running. Remember that this call can only be made by users in the MOVEit Log and/or MOVEit Admin groups.
Option Explicit ' Writes out a single task status Sub DumpTaskStatus(oAPI, StatusXML, iii) ShowMsg "===== " & oAPI.GetValue(StatusXML, "TaskName", iii) & _ " (" & _ oAPI.GetValue(StatusXML, "TaskID", iii) & _ ") =====" ShowMsg "= Started : " & oAPI.GetValue(StatusXML, "TimeStarted", iii) & _ " (" & _ oAPI.GetValue(StatusXML, "StartedBy", iii) & _ ")" Dim ShortStatus ShortStatus = oAPI.GetValue(StatusXML, "Status", iii) if Len(ShortStatus) > 50 then ShortStatus = Mid(ShortStatus, 1, 50) & "..." ShowMsg "= Status : " & ShortStatus if oAPI.GetValue(StatusXML, "TotFileBytes", iii) > 0 then ShowMsg "= Transfer: " & oAPI.GetValue(StatusXML, "CurFileBytes", iii) & _ " of " & _ oAPI.GetValue(StatusXML, "TotFileBytes", iii) & _ " bytes" end if End Sub ' Echo a message to the console Sub ShowMsg(MyText) Dim TheSplit TheSplit = Split(Now()," ") WScript.Echo TheSplit(1) & " - " & MyText End Sub ' Echo a message to the console along with last API error (if any) Sub ShowMsg2(MyText,oAPI) Dim TheSplit TheSplit = Split(Now()," ") if oAPI.GetErrorCode = 0 then WScript.Echo TheSplit(1) & " - " & MyText else WScript.Echo TheSplit(1) & " - " & MyText & " Error#" & oAPI.GetErrorCode & ": " & oAPI.GetErrorDescription end if End Sub '--- Sub Main ------------------------------------------------ Sub Main ShowMsg "showrunningtasks.vbs running" Dim bOK Dim TaskHnd, WaitResult, TaskName, WaitSecs Dim oAPI Set oAPI = CreateObject("MICentralAPICOM.MICentralAPI") oAPI.SetHost("localhost") oAPI.SetUser("miadmin") oAPI.SetPassword("password") bOK = oAPI.Connect() if NOT bOK then ShowMsg2 "Could not sign on to MOVEit Automation!",oAPI Exit Sub end if ShowMsg("Running API version " & oAPI.GetAPIVersion() & _ " on Central version " & oAPI.GetCentralVersion() ) Dim reply, HTab, TaskCount, iii HTab = chr(9) reply = oAPI.ShowRunningTasks() reply = Replace(reply, HTab, " ") ' Remove tabs for readability If "" = reply OR oAPI.GetErrorCode > 0 Then ShowMsg2 "Failed to get status: ", oAPI Exit Sub Else TaskCount = UBound(Split(reply,"<Task>")) ' Count how many tasks are running ShowMsg "Scheduler Status: " & oAPI.GetValue(reply, "SchedulerStatus", 1) ShowMsg "Tasks Running: " & TaskCount if TaskCount > 0 then for iii = 1 to TaskCount DumpTaskStatus oAPI, reply, iii next 'iii end if ShowMsg "Full XML Reply: " & reply End If ShowMsg "showrunningtasks.vbs stopped" End Sub Main
Sample Output (With Proper Credentials)
5:01:31 - showrunningtasks.vbs running 5:08:16 - Running API version 4.9.1.0 on Central version 4.9.2.5 5:01:31 - Scheduler Status: On 5:01:31 - Tasks Running: 3 5:01:31 - ===== Disk Cache Clear Test 1b (104874969) ===== 5:01:31 - = Started : 2007-10-19 17:01:28 (Via NextTask) 5:01:31 - = Status : Running script Sleep 5:01:31 - ===== Disk Cache Clear Test 3a (208385491) ===== 5:01:31 - = Started : 2007-10-19 17:01:26 (Via NextTask) 5:01:31 - = Status : Copying d:/temp/diskcachetest3/MOVEitDMZ.chm from ... 5:01:31 - = Transfer: 720896 of 1689452 bytes 5:01:31 - ===== Disk Cache Clear Test 2a (659952116) ===== 5:01:31 - = Started : 2007-10-19 17:01:26 (Via NextTask) 5:01:31 - = Status : Copying d:/temp/diskcachetest2/MIDMZ22.exe from fi... 5:01:31 - = Transfer: 5695488 of 5695488 bytes 5:01:31 - Full XML Reply:<CmdName>SHOWRUNNINGTASKS</CmdName> <ReqID>3</ReqID> <RepCode>0</RepCode> <RepText></RepText> <Time>2007-10-19 17:01:31</Time> <Output><Tasks><SchedulerStatus>On</SchedulerStatus> <Task><TaskID>104874969</TaskID> <TaskName>Disk Cache Clear Test 1b</TaskName> <NominalStart>2007-10-19 17:01:28</NominalStart> <TimeStarted>2007-10-19 17:01:28</TimeStarted> <StartedBy>Via NextTask</StartedBy> <Status>Running script Sleep</Status> <CurFileBytes>0</CurFileBytes> <TotFileBytes>-1</TotFileBytes> <LastErrorType>0</LastErrorType> <LastErrorText></LastErrorText> </Task> <Task><TaskID>208385491</TaskID> <TaskName>Disk Cache Clear Test 3a</TaskName> <NominalStart>2007-10-19 17:01:26</NominalStart> <TimeStarted>2007-10-19 17:01:26</TimeStarted> <StartedBy>Via NextTask</StartedBy> <Status>Copying d:/temp/diskcachetest3/MOVEitDMZ.chm from filesystem</Status> <CurFileBytes>720896</CurFileBytes> <TotFileBytes>1689452</TotFileBytes> <LastErrorType>0</LastErrorType> <LastErrorText></LastErrorText> </Task> <Task><TaskID>659952116</TaskID> <TaskName>Disk Cache Clear Test 2a</TaskName> <NominalStart>2007-10-19 17:01:26</NominalStart> <TimeStarted>2007-10-19 17:01:26</TimeStarted> <StartedBy>Via NextTask</StartedBy> <Status>Copying d:/temp/diskcachetest2/MIDMZ22.exe from filesystem</Status> <CurFileBytes>5695488</CurFileBytes> <TotFileBytes>5695488</TotFileBytes> <LastErrorType>0</LastErrorType> <LastErrorText></LastErrorText> </Task> </Tasks></Output> </Response> 5:01:31 - showrunningtasks.vbs stopped
Sample Output (Without Proper Credentials)
5:08:15 - showrunningtasks.vbs running 5:08:16 - Running API version 4.9.1.0 on Central version 4.9.2.5 5:08:16 - Failed to get status: Error#2020: You do not have sufficient permissi ons for this command.