L'outil connu de tous IISReset.exe qui permet de redémarrer un serveur web IIS est très utile pour un dévelppeur.
On peut regretter que ce type d'outil n'existe pas pour BizTalk Server.
 
En utilisant le commande WMI, on peut assez facilement recréer cet outil : BTSReset
 
using System;
using System.Text;
using System.Management;

namespace BizTalkFactory.BTSReset
{
   /// <summary>
   /// Command line application that can stop,
   /// start or restart the BizTalk Application
   /// hosts on the local machine.
   /// </summary>
   class BtsResetApp
   {
      [Flags]
      enum Options
      {
         Stop = 0x01,
         Start = 0x10,
         Reset = Stop | Start
      }
      public static void Main(string[] args)
      {
         Options opts = Options.Reset;
         if ( args.Length == 0 ) {
            opts = Options.Reset;
         } else if ( args[0] == "stop" ) {
            opts = Options.Stop;
         } else if ( args[0] == "start" ) {
            opts = Options.Start;
         } else {
            PrintUsage();
            return;
         }
         ProcessOptions(opts);
      }
      private static void ProcessOptions(Options opts)
      {
         EnumerationOptions enumOptions = new EnumerationOptions();
         enumOptions.ReturnImmediately = false;
         ManagementObjectSearcher searcher = new ManagementObjectSearcher (
                           "root\\MicrosoftBizTalkServer",
                           "Select * from MSBTS_HostInstance where HostType=1",
                           enumOptions
                        );
         if ( (opts & Options.Stop) != 0 )
         {
            foreach ( ManagementObject inst in searcher.Get() )
            {
               if ( (UInt32)inst["ServiceState"] != 1 ) {
                  Console.WriteLine("Stopping {0}...", inst["HostName"]);
                  inst.InvokeMethod("Stop", null);
               }
            }
         }
         if ( (opts & Options.Start) != 0 )
         {
            foreach ( ManagementObject inst in searcher.Get() )
            {
               if ( (UInt32)inst["ServiceState"] == 1 ) {
                  Console.WriteLine("Starting {0}...", inst["HostName"]);
                  inst.InvokeMethod("Start", null);
               }
            }
         }
         searcher.Dispose();
      }
      private static void PrintUsage()
      {
         Console.WriteLine("usage: btsreset.exe [start | stop]");
         Console.WriteLine("   no arguments = restart all host instances");
         Console.WriteLine("   start = start all stopped host instances");
         Console.WriteLine("   stop = stop all started host instances");
      }
   } // class
}

Publié le 17/05/2008  par Michel Hubert