electronic wonderl@nd

the weblog of campbell mcneill
posts - 16, comments - 13, trackbacks - 12

My Links

News

Archives

Post Categories

My Stuff

People I Know

Tuesday, April 05, 2005

Adding / Removing a BizTalk Adapter using a Custom Action

Just been working on getting a BizTalk adapter to install using windows installer. I used the adpater wizard to create the adapter, which kindly provides a nice .reg file to handle the registry stuff. This is nice and easy to use in conjunction with the registry editor function of the setup project in VS.NET. What I also wanted to do was add in support for getting the adapter to show up in the BizTalk admin and also remove it from there when you uninstall it. You can do this by using WMI in a custom action. First what you need to do is add an installer class to your adapter project. You can do this using visual studio. This is covered in the documentataion. Then you need to add in the following statment at the top. You also need to add in the System.Management assembly.

using System.Management;

For the install action, use the following, changing the relevant sections:
            //Run the base class stuff.
            base.Install(stateSaver);
 
            try
            {
 
                PutOptions options = new PutOptions();
                options.Type = PutType.CreateOnly;
 
                //create a ManagementClass object and spawn a ManagementObject instance
                ManagementClass newAdapterClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_AdapterSetting", null);
                ManagementObject newAdapterObject = newAdapterClass.CreateInstance();
           
                //set the properties for the Managementobject
                newAdapterObject["Name"] = "<YOURADAPTER>";
                newAdapterObject["Comment"] = "<Comment you want to appear in BizTalk>";
                newAdapterObject["Constraints"] = "<Constraint Bit Mank>";  //Bitmask appears in registry file.
                newAdapterObject["MgmtCLSID"] = "<Adapter Management Class Id>"; //Guid that appears in the registry file.            
                //create the Managementobject
                newAdapterObject.Put(options);
                System.Diagnostics.Trace.WriteLine("Adapter has been created successfully");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                throw;
            }
And the following for the uninstall:
            try
            {
                ManagementClass adapterClass = new ManagementClass("root\\MicrosoftBizTalkServer", "MSBTS_AdapterSetting", null);
                ManagementObjectCollection adapterObjects = adapterClass.GetInstances();
 
                System.Diagnostics.Trace.WriteLine("We have {0} management objects", adapterObjects.Count.ToString());
 
                foreach (ManagementObject adapterObject in adapterObjects)
                {
                    System.Diagnostics.Trace.WriteLine("Current adapter object is {0}", adapterObject["Name"].ToString());
 
                    if( adapterObject["Name"].ToString().ToUpper() == "<YOURADAPTER>" )
                        adapterObject.Delete();
                }
                System.Diagnostics.Trace.WriteLine("Adapter has been removed successfully");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                throw;
            }

posted @ Tuesday, April 05, 2005 10:13 PM | Feedback (3) |

New Blog

Hi All,

Welcome to my new blog. My old hosting let me down so will be working on getting some content on this one ASAP to keep the readers interested.

posted @ Tuesday, April 05, 2005 10:07 PM | Feedback (1) |

Powered by: