public static Status AddSendHostHandler(string Adapter, string HostName) { Status operationStatus = new Status(); try { PutOptions options = new PutOptions(); options.Type = PutType.UpdateOnly; //Look for the target WMI Class MSBTS_SendHandler2 instance string strWQL = "SELECT * FROM MSBTS_SendHandler2 WHERE AdapterName = '" + Adapter + "'"; ManagementObjectSearcher searcherSendHandler = new ManagementObjectSearcher(new ManagementScope("root\\MicrosoftBizTalkServer"), new WqlObjectQuery(strWQL), null); foreach (ManagementObject objSendHandler in searcherSendHandler.Get()) { objSendHandler.SetPropertyValue("HostNameToSwitchTo", HostName); objSendHandler.Put(); } operationStatus.Message = "Send Adapter " + Adapter + " set to use Host " + HostName; } catch (Exception exception) { operationStatus.Message = exception.Message; operationStatus.State = OperationState.FAILURE; } return operationStatus; }
public static Status InstallHosts(string ServerName, string HostName, string UserName, string Password, bool StartHost) { Status operationStatus = new Status(); try { PutOptions options = new PutOptions(); options.Type = PutType.CreateOnly; ObjectGetOptions bts_objOptions = new ObjectGetOptions(); // Creating instance of BizTalk Host. ManagementClass bts_AdminObjClassServerHost = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_ServerHost", bts_objOptions); ManagementObject bts_AdminObjectServerHost = bts_AdminObjClassServerHost.CreateInstance(); // Make sure to put correct Server Name,username and // password bts_AdminObjectServerHost["ServerName"] = ServerName; bts_AdminObjectServerHost["HostName"] = HostName; bts_AdminObjectServerHost.InvokeMethod("Map", null); ManagementClass bts_AdminObjClassHostInstance = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostInstance", bts_objOptions); ManagementObject bts_AdminObjectHostInstance = bts_AdminObjClassHostInstance.CreateInstance(); bts_AdminObjectHostInstance["Name"] = "Microsoft BizTalk Server " + HostName + " " + ServerName; //Also provide correct user name and password. ManagementBaseObject inParams = bts_AdminObjectHostInstance.GetMethodParameters("Install"); inParams["GrantLogOnAsService"] = false; inParams["Logon"] = UserName; inParams["Password"] = Password; bts_AdminObjectHostInstance.InvokeMethod("Install", inParams, null); if (StartHost) { bts_AdminObjectHostInstance.InvokeMethod("Start", null); } operationStatus.Message = "Host - " + HostName + " - has been installed. \r\n"; } catch (Exception exception) { operationStatus.Message = exception.Message; operationStatus.State = OperationState.FAILURE; } return operationStatus; }
public static Status MakeHost(string HostName, string Type, string HostNTGroup, bool AuthTrusted) { Status operationStatus = new Status(); try { PutOptions options = new PutOptions(); options.Type = PutType.CreateOnly; // create a ManagementClass object and spawn a ManagementObject instance ManagementClass objHostSettingClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_HostSetting", null); ManagementObject objHostSetting = objHostSettingClass.CreateInstance(); // set the properties for the Managementobject // Host Name objHostSetting["Name"] = HostName; // Host Type if (Type == "Isolated") objHostSetting["HostType"] = HostType.Isolated; else objHostSetting["HostType"] = HostType.InProcess; objHostSetting["NTGroupName"] = HostNTGroup; objHostSetting["AuthTrusted"] = AuthTrusted; //create the Managementobject objHostSetting.Put(options); operationStatus.Message = Type + " Host - " + HostName + " - has been created."; } catch (Exception exception) { operationStatus.Message = exception.Message; operationStatus.State = OperationState.FAILURE; } return operationStatus; }