Visual Basic Code Example: Retrieving MSMQQueueInfo.PathName


This example provides a function that receives the GUID of an existing public queue and returns the MSMQQueueInfo.PathName property for it, which can be used to display the path name of the queue. The queue GUID is supplied to this function as a string representation of the GUID in the form 12345678-1234-1234-1234-123456789ABC.


The string must not include the braces normally used with GUIDs.

This function must retrieve information stored in the directory service to return the path name of an existing public queue.

To retrieve MSMQQueueInfo.PathName

  1. Declare the objects needed to retrieve queue properties. This routine declares an MSMQQueueInfo object.

  2. Create the MSMQQueueInfo object. This example then uses MSMQQueueInfo.FormatName to set the format name to the format name created from the GUID string passed to the function.

  3. Call MSMQQueueInfo.Refresh to obtain the current registered settings of the queue properties.


This call retrieves the settings of all properties of the queue with the format name set. If no such queue exists, an error message is displayed

  1. Return the local setting of MSMQQueueInfo.PathName.

The following code example can be run on all versions of Message Queuing.

Function GetQueuePathname( _
                          QueueGuid As String _
                          ) As String
  Dim qinfo As MSMQQueueInfo

  ' Create the MSMQQueueInfo object.
  Set qinfo = New MSMQQueueInfo
  qinfo.FormatName = "PUBLIC=" & QueueGuid
  On Error GoTo ErrorHandler

  ' Retrieve the internally registered property values.

  'Return the local setting of MSMQQueueInfo.PathName
  GetQueuePathname = qinfo.PathName
  Exit Function

  MsgBox "Error " + Hex(Err.Number) + " was returned." _
          + Chr(13) + Err.Description
End Function

Community Additions