Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista
The MQCreateQueue function creates a public or private queue based on the queue properties provided.
HRESULT APIENTRY MQCreateQueue( PSECURITY_DESCRIPTOR pSecurityDescriptor, MQQUEUEPROPS * pQueueProps, LPWSTR lpwcsFormatName, LPDWORD lpdwFormatNameLength );
[in] Pointer to a SECURITY_DESCRIPTOR structure that specifies the user-defined security information that will be associated with the queue. The default values are used for any components of the queue's security that are not specified in this structure. If this parameter is set to a NULL pointer, all the default values are used. Following are the default values of the components of a queue's security information:
The security identifier (SID) of the queue's creator.
The security identifier (SID) of the primary group to which the queue's creator belongs.
Discretionary access control list (DACL)
Full control for the creator of the queue. All other users (processes) can get queue properties, get queue security, and send messages to the queue. In MSMQ 3.0, anonymous users can only send messages to the queue, and the Computer_Name$ account of a computer that belongs to a domain can only get the properties and security of the queue and receive or peek at messages in the queue.
System access control list (SACL)
[in, out] Pointer to the MQQUEUEPROPS structure that specifies the properties of the queue.
On output, the optional aStatus array, if it was included in MQQUEUEPROPS, indicates the status of the properties.
[out] Pointer to buffer to receive the format name for the queue (a NULL pointer is allowed). This buffer is called the format name buffer. In domain mode, the buffer receives the public format name for a public queue or the private format name for a local private queue, whereas in offline or workgroup mode, the buffer can receive only the direct format name for a local private queue.
For definitions of terms in italics, see the Message Queuing Glossary.
[in, out] On input, specifies the length (in Unicode characters) of the format name buffer specified in lpwcsFormatName. Public queues require at least 44 Unicode characters; private queues require at least 54. If a NULL pointer is specified in lpwcsFormatName, set lpdwFormatNameLength to 0 (zero) on input.
On output, indicates the length of the returned format name string, including the null-terminating character. If the output value is greater than the initial input value, the supplied buffer is not large enough to contain the complete format name string and MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL is returned. In this case, the queue is created and only a portion of the format name is returned.
The access rights for creating a queue on this computer are not allowed for the calling process.
An illegal property value is specified.
PROPID_Q_PATHNAME contains an illegal Message Queuing path name string.
The SECURITY_DESCRIPTOR structure passed is invalid.
No Message Queuing path name was specified (PROPID_Q_PATHNAME).
The specified path name in PROPID_Q_PATHNAME contains the name of an unrecognized machine. For example, this code is returned when you try to create a queue on a machine where Message Queuing is not installed.
An invalid parameter was specified. For example, lpwcsFormatName is set to a NULL pointer and lpdwFormatNameLength is not set to 0 (zero) on input set.
A connection with the directory service cannot be established. Verify permissions for accessing the directory service.
One or more properties resulted in an error.
A specified property is not valid when creating the queue.
A queue with an identical Message Queuing path name or instance already exists.
The Message Queuing service is not available.
The queue cannot be added to the MSMQ Information Store (MQIS) because a new MQIS server is being installed.
The queue was created successfully, but the size of the buffer for receiving the format name of the created queue is too small.
The function completed, but one or more properties resulted in a warning.
Apart from generic Message Queuing error codes, this function may return ADSI and LDAP error codes. For example, LDAP_BUSY (0x8007200E) is returned when the directory service server is busy.
You must always specify the PROPID_Q_PATHNAMEE property before calling MQCreateQueue. The PROPID_Q_PATHNAME property tells Message Queuing where to store the messages sent to the queue, whether the queue is public or private, and the name of the queue. A local or remote computer can be specified for a public queue, but only the local computer can be specified for a private queue. When setting this property you can specify the UNC or DNS path name for the queue.
Setting other queue properties is optional. If a property is not specified in the pQueueProps parameter, Message Queuing uses its default value when creating the queue. After the queue is created, its properties can be changed by calling MQSetQueueProperties.
Message Queuing registers public queues in the directory service and private queues on the local computer specified. All queues exist until deleted explicitly.
Private queues can be created only on the local computer. When a private queue is created, Message Queuing stores a description of the queue in the Lqs folder on the local computer (by default, %windir%\System32\MSMQ\Storage\Lqs in MSMQ 2.0 and later, and \Program Files\MSMQ\Storage\Lqs in MSMQ 1.0). Applications must ensure that no other private queues with the same name exist on a local computer. If a queue with the same name already exists, Message Queuing will return an MQ_ERROR_QUEUE_EXISTS error when MQCreateQueue is called.
When a private queue is created on a computer operating in domain mode, a query is sent to the directory service to obtain information from the security descriptor of the MSMQ-Configuration object, which the local Message Queuing service uses to verify that the user has the permissions needed to create a queue.
An MSMQ 3.0 computer that belongs to a Windows® 2000 or Windows Server 2003 domain uses ADSI to create a public queue and grants anonymous users the permission to send messages to the queue. Because an MSMQ 3.0 computer that belongs to an MSMQ 1.0 enterprise cannot use ADSI to create a queue, it sends an RPC call to an MQIS server to create the queue. The queue is then created with the MSMQ 1.0 default security descriptor, which does not include ANONYMOUS.
To create a transactional queue, set the PROPID_Q_TRANSACTION property to MQ_TRANSACTIONAL. This property cannot be changed once the queue is created.
Foreign queues must be public queues. Their PROPID_Q_PATHNAME property must specify the name of the foreign computer as it is defined in the directory service. For information on connecting to foreign queues, see Connector Services.
Access control for the queue is based on the information supplied in the SECURITY_DESCRIPTOR structure specified in the pSecurityDescriptor parameter. The default values are used for any components of the queue's security that are not specified in this structure. If this parameter is set to a NULL pointer, all the default values are used. For information on access control, see Access Control.
Returned format name
The queue's returned format name is invalid if MQCreateQueue fails for any reason, including returning the error MQ_ERROR_QUEUE_EXISTS. If the call returns MQ_INFORMATION_FORMATNAME_BUFFER_TOO_SMALL, this means that the queue was created, but the format name could not fit in the format name buffer.
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 routing servers (FRS). For information on offline operations, see Message Queuing Offline Support.
When creating a public queue, some clients may not be able to see the new queue registered in the directory service even though the queue exists. Changes to the directory service (such as creating a public queue) are replicated from domain controller to domain controller, which can cause delays in the availability of new information. Consequently, clients using a specific domain controller may not be able to open the queue, even though it exists. Replication delays, including communication network delays such as down links, are controlled by the Message Queuing administrator.
Equivalent COM Method
When using COM components, you can create a public or private queue by calling the MSMQQueueInfo.Create method.
|For information on||See|
|The different types of queues provided by Message Queuing||Queues|
|What information Message Queuing needs to create queues||Creating Message Queues|
|Optional queue properties that can be set when you create a queue||Setting Queue Behavior|
|Transaction support provided by Message Queuing||Transactions|
The following code examples are included in Using Message Queuing.
|For an example of||See|
|Creating a public or private queue||C/C++ Code Example: Creating a Queue|
|Creating a transactional queue||C/C++ Code Example: Creating a Transactional Queue|
|Creating a security descriptor that gives a specified trusted user full control over a queue||C/C++ Code Example: Creating a Security Descriptor|
Windows NT/2000/XP: Included in Windows NT 4.0 SP3 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Mq.h.
Library: Use Mqrt.lib.