Salvataggio di un messaggio in un file tramite WMI

 

Usare il codice seguente per salvare un messaggio in un file usando MSBTS_TrackedMessageInstance.

using System.Management;  
  
      //Sample to show how to save a tracked message out to a file folder using MSBTS_TrackedMessageInstance class  
      public void SaveTrackedMessageInstanceToFolder(Guid MessageInstanceId, string strOutputFolder)  
      {  
         try  
         {  
            // Construct full WMI path to the MSBTS_TrackedMessageInstance using the message guid (NOTE: MessageInstanceID string value must be enclosed in {} curly brackets)  
            string strInstanceFullPath = "root\\MicrosoftBizTalkServer:MSBTS_TrackedMessageInstance.MessageInstanceID='{" + MessageInstanceId.ToString() + "}'";  
  
            // Load the MSBTS_TrackedMessageInstance  
            ManagementObject objTrackedSvcInst = new ManagementObject(strInstanceFullPath);  
  
            // Invoke "SaveToFile" method to save the message out into the specified folder  
            objTrackedSvcInst.InvokeMethod("SaveToFile", new object[] {strOutputFolder});  
         }  
         catch(Exception excep)  
         {  
            Console.WriteLine("Failed to save tracked message with id " + MessageInstanceId.ToString() + " into folder " + strOutputFolder + ": " + excep.Message);  
         }  
      }     
Option Explicit  
  
Sub SaveTrackedMessageInstanceToFolder(strMessageInstanceId, strOutputFolder)  
  
   On Error Resume Next  
  
   ' Construct full WMI path to the MSBTS_TrackedMessageInstance using the message guid (NOTE: MessageInstanceID string value must be enclosed in {} curly brackets)  
   Dim strInstanceFullPath : strInstanceFullPath = "MSBTS_TrackedMessageInstance.MessageInstanceID=""{" & strMessageInstanceId & "}"""  
  
   ' Load the MSBTS_TrackedMessageInstance  
   Dim objLocator : Set objLocator = CreateObject("WbemScripting.SWbemLocator")  
   Dim objServices : Set objServices = objLocator.ConnectServer(, "root/MicrosoftBizTalkServer")  
   CheckWMIError  
  
   Dim objTrackedMsgInst : Set objTrackedMsgInst = objServices.Get(strInstanceFullPath)  
   CheckWMIError  
  
   ' Invoke "SaveToFile" method to save the message out into the specified folder  
   objTrackedMsgInst.SaveToFile strOutputFolder  
   CheckWMIError  
  
   wscript.echo "Successfully saved tracked message with ID '" & strMessageInstanceId & "' into folder '" & strOutputFolder &"'"  
  
End Sub  
  
'This subroutine deals with all errors using the WbemScripting object.  Error descriptions  
'are returned to the user by printing to the console.  
Sub   CheckWMIError()  
  
   If Err <> 0   Then  
      On Error Resume   Next  
  
      Dim strErrDesc: strErrDesc = Err.Description  
      Dim ErrNum: ErrNum = Err.Number  
      Dim WMIError : Set WMIError = CreateObject("WbemScripting.SwbemLastError")  
  
      If ( TypeName(WMIError) = "Empty" ) Then  
         wscript.echo strErrDesc & " (HRESULT: "   & Hex(ErrNum) & ")."  
      Else  
         wscript.echo WMIError.Description & "(HRESULT: " & Hex(ErrNum) & ")."  
         Set WMIError = nothing  
      End   If  
  
      wscript.quit 0  
   End If  
  
End Sub   

Vedere anche

Esempi di script WMI
MSBTS_TrackedMessageInstance (WMI)