Manage active orchestration instances

May 2nd, 2008 by admin
'------------------------------------------------------------------
' Save as "ManageActiveOrchestrations.vbs"
' WMI script to manage active Orchestration instances
'
' Marcel Tiews in 05
'------------------------------------------------------------------

Option Explicit

Const SState_ReadyToRun = 1
Const SState_Active = 2
Const SState_SuspendedResumable = 4
Const SState_Dehydrated = 8
Const SState_Completed = 16
Const SState_SuspendedNotResumable = 32
Const SState_InBreakpoint = 64

EnumInstances

Sub EnumInstances()

   Dim objArgs: Set objArgs = WScript.Arguments
   Dim StdIn : Set StdIn = WScript.StdIn

   on error resume next

   Dim strOrchName : strOrchName = ""
   Dim strChangeStatus : strChangeStatus = "no"

   If Err <> 0 Then
      PrintWMIErrorThenExit Err.Description, Err.Number, false
   End If

   If (objArgs.Count > 0) Then
      strOrchName = ” where AssemblyName like “”" & objArgs(0) & “”"”
   If (objArgs.Count > 1) Then
      strChangeStatus = objArgs(1)
   End If
   Else
      PrintUsage()
      wscript.quit 1
   End If

   Dim strQuery, InstSet, Inst

   strQuery = “SELECT * FROM MSBTS_ServiceInstance ” & strOrchName
   set InstSet = GetObject(”Winmgmts:!root\MicrosoftBizTalkServer”).ExecQuery(strQuery)
   wscript.echo strQuery
   wscript.echo
   wscript.echo “…Please wait, this could take a while…”

   ‘Check for error condition before continuing.
   If Err <> 0 Then
      PrintWMIErrorThenExit Err.Description, Err.Number, false
   End If

   ‘Report on number of instances…
   Dim strCommand
   wscript.echo InstSet.Count & ” Instances were found.”
   wscript.echo
   If InstSet.Count > 0 Then
      For Each Inst In InstSet
         wscript.echo ” Instance-ID: ” & Inst.InstanceID
         wscript.echo ”    ServiceName: ” & Inst.ServiceName
         wscript.echo ”    Assembly: ” & Inst.AssemblyName & ” (” & Inst.AssemblyVersion & “)”
         wscript.echo ”    Status: ” & PrintStatus(Inst.ServiceStatus)

      If(strChangeStatus = “yes”) Then
         wscript.echo
         wscript.echo “Action: [r]esume | [s]uspend | [t]erminate”
         strCommand = StdIn.ReadLine
         If ( strCommand = “r” ) Then
            Inst.Resume
         Elseif ( strCommand = “t” ) Then
            Inst.Terminate
         Elseif ( strCommand = “s” ) Then
            Inst.Suspend
         Else
            wscript.echo “!!!Nothing done!!!”
         End If
         If Err <> 0 Then
            PrintWMIErrorThenExit Err.Description, Err.Number, true
         End If
      End If
      wscript.echo
      next
   End If

End Sub

Function PrintStatus(ServiceStatus)
   Select case ServiceStatus
   Case SState_ReadyToRun
         PrintStatus = “ReadyToRun”
   Case SState_Active
      PrintStatus = “Active”
   Case SState_SuspendedResumable
      PrintStatus = “SuspendedResumable”
   Case SState_Dehydrated
      PrintStatus = “Dehydrated”
   Case SState_Completed
      PrintStatus = “Completed”
   Case SState_SuspendedNotResumable
      PrintStatus = “SuspendedNotResumable”
   Case SState_InBreakpoint
      PrintStatus = “InBreakpoint”
   Case Else
      PrintStatus = “Unknown”
   End Select
End Function

Sub PrintWMIErrorThenExit(strErrDesc, ErrNum, ContinueOnError)
   On Error Resume Next
   Dim objWMIError : Set objWMIError =   CreateObject(”WbemScripting.SwbemLastError”)

   If ( TypeName(objWMIError) = “Empty” ) Then
      wscript.echo strErrDesc & ” (HRESULT: ” & Hex(ErrNum) & “).”
   Else
      wscript.echo objWMIError.Description & “(HRESULT: ” & Hex(ErrNum) & “).”
      Set objWMIError = nothing
   End If

   If(ContinueOnError=false) Then
      wscript.quit 0
   End If
End Sub

Sub PrintUsage()
   WScript.Echo “Usage:” + Chr(10) + Chr(10) + _
   “cscript ManageActiveOrchestrations.vbs  [yes|no]” + _
   Chr(10) + Chr(10) + ” Where: ” + Chr(10) + _
   ”   = The Name of the Assembly.” + Chr(10) + _
   ”  [yes|no] = Show dialog to terminate/suspend/resume instances.” + Chr(10)
End Sub

Posted in Biztalk, Development |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Recent Posts

Tags

Calendar

May 2008
M T W T F S S
    Jun »
 1234
567891011
12131415161718
19202122232425
262728293031  

PocketPC

Categories