Biztalk 2004 Integration Experiences

Monday, February 07, 2005

Restart all Biztalk In-Process Hosts using WMI

I am currently working on a Deployment Tool which can handle both BTS Assemblies Un-Deployment/Deployment with support to remove/add referrenced assemblies.

I started writing this tool in C#, still working on it and quickly noticed the value for common generic functions to help with Deployment/Un-Deployment.

The following C# Code illustrates how all the Biztalk In-Process Hosts can be re-started using WMI.

private static void RestartBiztalkInprocessHosts()
{
System.Management.EnumerationOptions enumOptions =
new System.Management.EnumerationOptions();
enumOptions.ReturnImmediately = false;
// HostType = 1 for In-Process Hosts
string strQuery = "Select * from MSBTS_HostInstance where HostType=1";

System.Management.ManagementObjectSearcher objSearch =
new System.Management.ManagementObjectSearcher
("root\\MicrosoftBizTalkServer",strQuery,enumOptions);

foreach(System.Management.ManagementObject inst in objSearch.Get())
{
//Check if ServiceState is 'Running'
if(inst["ServiceState"].ToString() == "4" )
{
inst.InvokeMethod("Stop",null);
inst.InvokeMethod("Start",null);
}
//Check if ServiceState is 'Stopped' or 'paused'
if(inst["ServiceState"].ToString() == "1"
inst["ServiceState"].ToString() == "7" )
inst.InvokeMethod("Start",null);
}

if (objSearch!= null)
objSearch.Dispose();
objSearch = null;

}

0 Comments:

Post a Comment

<< Home