This VBScript sample shows how to use the programmatic API to run an existing task and interpret the results.
' MICentralAPICOMDemo.vbs - VBScript demonstration of how to use the' COM version of the MOVEit Automation API. ' This script starts a task, waits for it to complete, and then reports ' information on the task run and the files it transferred. ' ' If you don't need the file transfer report, consider using the ' fully-supported MOVEit Automation command line client rather than ' writing your own script. ' ' Copyright © 2001-2022 Progress Software Corporation and/or one of its subsidiaries or affiliates. All rights reserved. https://community.progress.com/s/ ' ' Typical output from this script: ' ' Starting task Monthly Reports ' Task Monthly Reports has started ' TaskName = Monthly Reports ' TaskID = 133254349 ' TaskNominalStartTime = 2006-04-20 16:04:23 ' TaskTimeEnded = 2006-04-20 16:04:24 ' TaskErrorCode = 0 ' TaskErrorDescription = ' ' --- Information about the task run as a whole: --- ' TotalBytesSent = 36350 ' ' --- Information about the individual file transfers: --- ' Sent c:\tmp\two\test1.ggg (33408 bytes) ' Sent c:\tmp\two\test1.hhh (2942 bytes) Option Explicit Sub ShowMsg(MyText) WScript.Stdout.WriteLine MyText End Sub '--- Sub ShowTaskRunInfo --------------------------------------- ' Shows information about a completed task run--information ' about the task run as a whole. Sub ShowTaskRunInfo(oAPI, WaitResult) Dim strXMLTask, xmlDoc, oNode ' Fetch the information from MOVEit Automation, in XML format. strXMLTask = oAPI.GetTaskRunInfoXML(WaitResult) Set xmlDoc = CreateObject("msxml2.DOMDocument") xmlDoc.loadXML(strXMLTask) Set oNode = xmlDoc.selectSingleNode("/Records/Record/TotalBytesSent") ShowMsg "" ShowMsg "--- Information about the task run as a whole: ---" ShowMsg "TotalBytesSent = " & oNode.firstChild.nodeValue End Sub '--- Sub ShowTaskTransfers ------------------------------------- ' Shows information about files transferred by a task run. Sub ShowTaskTransfers(oAPI, WaitResult) Dim strXMLXfers, xmlDoc, fileNode, Action, DestFilename, NBytes ' Fetch the information from MOVEit Automation, in XML format. strXMLXfers = oAPI.GetTaskRunXfersXML(WaitResult) Set xmlDoc = CreateObject("msxml2.DOMDocument") xmlDoc.loadXML(strXMLXfers) ShowMsg "" ShowMsg "--- Information about the individual file transfers: ---" ' Loop through each file transfer record. ' Remember that there may be multiple records per transfer; ' in particular, a "get" and a "send" records for each. For Each fileNode In xmlDoc.selectNodes("/Records/Record") Action = fileNode.selectSingleNode("./Action").firstChild.nodeValue ' List only send records. If Action="send" Then DestFilename = fileNode.selectSingleNode("./DestFilename").firstChild.nodeValue NBytes = fileNode.selectSingleNode("./NBytes").firstChild.nodeValue ShowMsg "Sent " & DestFilename & " (" & NBytes & " bytes)" End If Next End Sub Sub Main() Dim oAPI, TaskHnd, WaitResult, TaskName, WaitSecs Set oAPI = CreateObject("MICentralAPICOM.MICentralAPI") oAPI.SetHost("localhost") oAPI.SetUser("username") oAPI.SetPassword("password") If Not oAPI.Connect() Then ShowMsg "Can't connect: " & oAPI.GetErrorDescription Exit Sub End If TaskName = "Monthly Reports" ShowMsg "Starting task " & TaskName ' Start the task. TaskHnd = oAPI.StartTask(TaskName, True, "") If "" = TaskHnd Then ShowMsg "Task " & TaskName & " failed to start" ShowMsg oAPI.GetErrorDescription Exit Sub Else ShowMsg "Task " & TaskName & " has started" End If WaitSecs = 120 ' Wait for the task to complete. Set WaitResult = oAPI.WaitForTasks(TaskHnd, WaitSecs) ' The task might not have completed within the timeout we selected. If Not WaitResult.HasCompletion Then ShowMsg "The task has not yet completed" Else ShowMsg "TaskName = " & WaitResult.TaskName ShowMsg "TaskID = " & WaitResult.TaskID ShowMsg "TaskNominalStartTime = " & WaitResult.TaskNominalStartTime ShowMsg "TaskTimeEnded = " & WaitResult.TaskTimeEnded ShowMsg "TaskErrorCode = " & WaitResult.TaskErrorCode ShowMsg "TaskErrorDescription = " & WaitResult.TaskErrorDescription ShowTaskRunInfo oAPI, WaitResult ShowTaskTransfers oAPI, WaitResult End If End Sub Main