Export (0) Print
Expand All

Visual Basic Code Example: Creating a Queue

This example provides a private function that creates a public or private queue based on a given queue path name. For creating transactional queues, see Visual Basic Code Example: Creating a Transactional Queue.

ms704021.note(en-us,VS.85).gifNote
Public queues cannot be created if there is no connection to the directory service. This restriction applies to dependent client computers, independent client computers that are working offline, and Message Queuing servers that have routing services enabled (for MSMQ 1.0, these servers are referred to as FRS servers).

The following procedure shows how the private function creates the queue.

To create a queue

  1. Declare the MSMQQueueInfo variable for the queue.

  2. Create a new MSMQQueueInfo object and assign it to the variable.

  3. Set the MSMQQueueInfo.PathName property to the UNC or DNS path name of the queue.

    The following are examples of UNC path names that can be used to create public and private queues for the local computer.

    .\testqueue                  ' Public queue path name.
    .\PRIVATE$\testqueue         ' Private queue path name.
    
ms704021.note(en-us,VS.85).gifNote
For Message Queuing dependent clients, the local computer is the client's supporting server.

  1. Set optional queue properties. This example also specifies the label of the queue using MSMQQueueInfo.Label.

  2. Call MSMQQueueInfo.Create to create the queue.

Example

The following code example contains no version-specific Message Queuing calls.

Sub CreateMyQueue( _
                  strPathname As String _
                  )
  Dim qinfo As MSMQQueueInfo
  
  Set qinfo = New MSMQQueueInfo
  qinfo.PathName = strPathname
  qinfo.Label = "TestQueue"
  
  On Error GoTo ErrorHandler
  qinfo.Create
  
  MsgBox "Created Queue."
  Exit Sub
  
ErrorHandler:
  MsgBox "Error " + Hex(Err.Number) + " was returned." _
          + Chr(13) + Err.Description
End Sub
Show:
© 2014 Microsoft