BizTalk Host Action Module

Microsoft.BizTalk.Server.2016.HostAction.Task (WriteActionModuleType)

This module is used for performing operations on a BizTalk host.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.BizTalk.ProbeAccount
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsThis is the timeout (in seconds) after which execution of the script associated with the module is terminated if not yet completed.

Source Code:

<WriteActionModuleType ID="Microsoft.BizTalk.Server.2016.HostAction.Task" Accessibility="Public" RunAs="Microsoft.BizTalk.ProbeAccount" Batching="false">
<Configuration>
<xsd:element name="TargetComputer" type="xsd:string"/>
<xsd:element name="HostName" type="xsd:string"/>
<xsd:element name="TaskOption" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>Microsoft.BizTalk.Server.2016.HostAction.vbs</ScriptName>
<Arguments>$Config/TargetComputer$ "$Config/HostName$" $Config/TaskOption$</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved.
'*************************************************************************
' $ScriptName: "Start/Stop/ Host" $
'
' Purpose - This script Start/Stop/ a Host.
'
' Parameters
' "TargetComputer" = the computer that we target this task
' "HostName" = the name of the Host
' "Option" = this is the task option (Start/Stop/)
'
' $File: Microsoft.BizTalk.Server.2016.HostAction.vbs $
'
'*************************************************************************
Option Explicit

Dim oArgs
Dim strNamespace, strQuery
Dim strHostName, strTargetComputer, strOption

Const EVENT_SOURCE = "Task Start/Stop/ Host"

'Event Type Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const HKEY_CLASSES_ROOT = &amp;H80000000
Const HKEY_CURRENT_USER = &amp;H80000001
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const HKEY_USERS = &amp;H80000003
Const HKEY_CURRENT_CONFIG = &amp;H80000005

Set oArgs = WScript.Arguments
if oArgs.Count &lt; 3 Then
Wscript.Quit -1
End If

strTargetComputer = oArgs(0)
strHostName = oArgs(1)
strOption = oArgs(2)
strNamespace = "\ROOT\MicrosoftBizTalkServer"
strQuery = "select * from MSBTS_Host where Name =""" &amp; Replace(strHostName, "\", "\\") &amp; """"

ExecActionOnHost

Sub ExecActionOnHost()
Dim strMessage
Dim objInstSet, objInst
On Error Resume Next
Set objInstSet = GetWMICollection(strTargetComputer, strNamespace, strQuery)

'Check for error condition before continuing.
If Err &lt;&gt; 0 Then
PrintWMIErrorThenExit Err.Description, Err.Number
End If

'If found, execute action, otherwise print error and end.
If objInstSet.Count &gt; 0 then
For Each objInst in objInstSet
Select Case strOption
Case "1"
objInst.Start
strMessage = "The Host was successfully Started."
Case "2"
objInst.Stop
strMessage = "The Host was successfully Stopped."
End Select
If Err &lt;&gt; 0 Then
PrintWMIErrorThenExit Err.Description, Err.Number
End If
WScript.Echo
Next
Else
WScript.Echo "No Host was found matching that Name."
End If
End Sub

Function GetWMICollection(TargetComputerToUse, strNamespace, strQuery)
Dim WbemSrv, WbemObjectSet
Set WbemSrv = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; TargetComputerToUse &amp; strNamespace)
Set WbemObjectSet = WbemSrv.ExecQuery(strQuery)
Set GetWMICollection = WbemObjectSet
End Function

'This subroutine deals with all errors using the WbemScripting object. Error descriptions
'are returned to the user by printing to the console.
Sub PrintWMIErrorThenExit(strErrDesc, nErrNum)
On Error Resume Next
Dim objWMIError : Set objWMIError = CreateObject("WbemScripting.SwbemLastError")

If ( TypeName(objWMIError) = "Empty" ) Then
WScript.Echo strErrDesc &amp; " (HRESULT: " &amp; Hex(nErrNum) &amp; ")."
Else
WScript.Echo objWMIError.Description &amp; "(HRESULT: " &amp; Hex(nErrNum) &amp; ")."
Set objWMIError = Nothing
End If

'bail out
WScript.Quit 0
End Sub

'=================================================================================
' Publish resulting performance data / Create events
'=================================================================================

Sub CreateEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, True
End Sub

Sub CreateReportEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, False
End Sub

Sub CreateEventEx(strSource, lngEventID, lngEventType, strMsg, strSrcComputer, blnIncScriptName)
Dim oAPI
Set oAPI = CreateObject("Mom.ScriptAPI")
Call oAPI.LogScriptEvent(strSource, lngEventID, lngEventType, strMsg)
End Sub
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>