All queues, either public or private, are created by calling the MSMQQueueInfo object's Create method. For a description of public and private queues, see Message Queues.
The only queue property required to create the queue is PathName. This property tells 1) MSMQ where to store the queue's messages, 2) whether the queue is public or private, and 3) the name of the queue. Once the queue is created, the MSMQQueueInfo object's returned FormatName property is used to open the queue. For a description of MSMQ pathnames and queue format names, see Referencing a Queue.
Note The MSMQ pathname must be unique in the MSMQ enterprise. This applies to public and private queues.
qinfo.PathName = "machinename\localname"
or
qinfo.PathName = "machinename\PRIVATE$\localname"
Where qinfo is an MSMQQueueInfo object.
qinfo.Create
The following two examples show functions used to create a public queue and a private queue. In these examples, two queue properties are specified: PathName and Label.
Note In these examples, "." is used to indicate the local machine in PathName. For MSMQ servers and independent clients, the local machine is the local computer. However, for MSMQ dependent clients, the local machine is the client's MSMQ server.
For a public queue
Function CreatePublicQueue() As MSMQQueueInfo
Dim qinfo As New MSMQQueueInfo
qinfo.PathName = ".\MyQueue" 'Created on local computer.
qinfo.Label = "Public Queue"
On Error GoTo ErrorHandler
qinfo.Create
Set CreatePublicQueue = qinfo
Exit Function
ErrorHandler:
MsgBox "Couldn't create queue. Error: " + Str$(Err.Number)
MsgBox "Reason: " + Err.Description
Set CreatePublicQueue = Nothing
End Function
Sub Test()
Dim qinfo As MSMQQueueInfo
Set qinfo = CreatePublicQueue
If Not qinfo Is Nothing Then
MsgBox "Queue's format name is: " = qinfo.FormatName
End If
End Sub
For a private queue
Function CreatePrivateQueue() As MSMQQueueInfo
Dim qinfo As New MSMQQueueInfo
qinfo.PathName = ".\Private$\MyQueue" 'On local computer.
qinfo.Label = "Private Queue"
On Error GoTo ErrorHandler
qinfo.Create
Set CreatePrivateQueue = qinfo
Exit Function
ErrorHandler:
MsgBox "Couldn't create queue. Error: " + Str$(Err.Number)
MsgBox "Reason: " + Err.Description
Set CreatePrivateQueue = Nothing
End Function
Sub Test()
Dim qinfo As MSMQQueueInfo
Set qinfo = CreatePrivateQueue
If Not qinfo Is Nothing Then
MsgBox "Queue's format name is: " = qinfo.FormatName
End If
End Sub
The following optional queue properties can be set by the application when creating the queue:
The following properties are set by MSMQ when it creates the queue. To read these properties, the application must explicitly call the MSMQQueueInfo object's Refresh method before they can be read.
CreateTime (public queues only)
FormatName (public and private queues)
IsTransactional (public and private queues)
ModifyTime (public queues only)
QueueGuid (public queues only)