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.
|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
Declare the MSMQQueueInfo variable for the queue.
Create a new MSMQQueueInfo object and assign it to the variable.
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.
|For Message Queuing dependent clients, the local computer is the client's supporting server.|
Set optional queue properties. This example also specifies the label of the queue using MSMQQueueInfo.Label.
Call MSMQQueueInfo.Create to create the queue.
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