'Variables
Dim oArgs,SourceType,SourceID,ManagedEntityId,TargetPricipalName,TargetDisplayName,P_LogSuccessEvent,dtStart,lExitCode,sStatus,lStatus,P_ManagementGroup
Dim service,rootFolder
dtStart = Now
Set oArgs = WScript.Arguments
if oArgs.Count < 1 Then
Wscript.Quit -1
End If
Dim oAPI,oBag
Set oAPI = CreateObject("Mom.ScriptAPI")
If (true = P_LogSuccessEvent) Then
LogParams
End IF
Set service = CreateObject("Schedule.Service")
call service.Connect()
Set rootFolder = service.GetFolder("\")
ProcessFolder rootFolder
Set rootFolder = Nothing
on error resume next
oAPI.ReturnItems
If (true = P_LogSuccessEvent) Then
Call LogEvent(STOP_EVENT_ID,EVENT_TYPE_SUCCESS, "has completed successfully in " & DateDiff("s", dtStart, Now) & " seconds.")
End IF
Sub ProcessFolder(Folder)
Dim registeredTask,SubFolder
For Each registeredTask In Folder.GetTasks(1)
if registeredTask.Enabled = True then
set oBag = oAPI.CreateTypedPropertyBag(StateDataType)
lExitCode = clng(registeredTask.LastTaskResult)
if (registeredTask.LastRunTime) = cdate(0) Then
lExitCode = "0"
end if
oBag.AddValue "ExitCode", cstr(lExitCode)
oBag.AddValue "ExitCodeHex", "0x" & fmt(CStr(Hex(lExitCode)))
oAPI.AddItem oBag
Set oBag = Nothing
end if
Next
For Each SubFolder In folder.GetFolders(1)
ProcessFolder SubFolder
next
End sub
Function fmt(sStat)
Dim lSize,i
lSize = Len(sStat)
for i = lSize to 7
sStat = "0" & sStat
next
fmt=sStat
End Function
Sub LogParams
DIm scmdLine, I, oArgs
sCmdLine = ""
Set oArgs = WScript.Arguments
for I=0 to oArgs.Count -1
sCmdLine = sCmdLine & " " & oArgs(I)
next
LogEvent START_EVENT_ID,EVENT_TYPE_SUCCESS,"Starting script. " & sCmdLine
End Sub
Sub LogEvent(eventID, eventType, msg)
WScript.Echo "Logging event. " & Wscript.ScriptName & " Version : " & SCRIPT_VER & " EventID: " & eventID & " eventType: " & eventType & " --> " & msg
Call oAPI.LogScriptEvent(Wscript.ScriptName,eventID,eventType, " Version : " & SCRIPT_VER & " " & msg)
End Sub