Code snippet dump! Our enterprise monitoring software needed to be able to iterate the running instances of BizTalk so that it could sample the appropriate performance counters. This is the 'alpha' version we are running with. Because of the way the performance counters are registered on a per instance basis, we needed the 'name' of the host and not necessarily the GUID associated with it. Since administrators could potentially move host instances from node to node, or create, etc (however unlikely) we wanted something that we wouldn't have to remember to maintain if an administrator changed the location of a host instance at 3am.
Other proposed options included:
- Iterate the BTSNTSvc.exe process and parsing the command-line looking for the host name - this tells us the running instance.
- Use the BizTalk WMI model to query for the information we needed - this is fairly rich object model.
- Iterate the HKLM\CurrentControlSet\Services registry node, looking for nodes that started with 'BTSNTSvc$' and parsing that value, though this didn't give us whether the host instance was actually running.
The code below expects to execute on the machine its querying for, a requirement of the execution model of our monitoring software.
Code: List Running BizTalk Host Instance Names
' MSBTS_HostInstance.ServiceState valid values
' More information regarding MSBS_HostInstance can be found on MSDN http://msdn2.microsoft.com/en-us/library/aa560660.aspx
computerName = GetLocalComputerName()
' returns a wmi object set of MSBTS_HostInstance objects
Set hosts = GetRunningBizTalkHosts( computerName )
for each host in hosts
' do something for each host
set wmi = GetObject("winmgmts:\\.\root\cimv2")
Set systemInfo = wmi.ExecQuery("Select * From Win32_ComputerSystem")
for each propertyName in systemInfo
computerName = propertyName.Name
GetLocalComputerName = computerName
Set hosts = GetObject("Winmgmts:!root\MicrosoftBizTalkServer").ExecQuery("SELECT * FROM MSBTS_HostInstance WHERE RunningServer = '" & machineName & "' AND ServiceState = 4")
Set GetRunningBizTalkHosts = hosts