This post disappeared from a previous blog of mine so I'm reposting it.


A couple of weeks ago I wrote a short article about an ‘easy’ method of determining the correct BTSNTSvc.exe process to attach to in VS.NET in order to debug orchestration utility components.  Scott Colestock described a better way to determine this here.


I liked his method much better than mine but I didn’t want to have Perfmon open whenever I needed to find the correct process id.  I took his suggestion one step further and created a simple console application that writes out the process ids of all started, in-process host instances.  Here are the steps to create (using C#) and use this simple application:


  1. Create a new .NET console application.
  2. Add a reference to System.Management.dll
  3. In the class that contains your main() method add using statements for:
    1. System.Diagnostics
    2. System.Management
  4. Add the following code to the main() method:


                  //Enumerate all HostInstances of "InProcess" type



                        //Create EnumerationOptions

                        EnumerationOptions enumOptions = new EnumerationOptions();

                        enumOptions.ReturnImmediately = false;


                        //Search for all HostInstances of 'InProcess' type in the Biztalk namespace scope

                        ManagementObjectSearcher searchObject = new ManagementObjectSearcher("root\\MicrosoftBizTalkServer","Select * from MSBTS_HostInstance where HostType=1 and ServiceState=4",enumOptions);