Updated: July 19, 2016

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

(Introduced in MSMQ 3.0.) The MQMgmtAction function changes the state of a computer or a queue.

HRESULT MQMgmtAction(  
  LPCWSTR pMachineName,    
  LPCWSTR pObjectName,    
  LPCWSTR pAction         


[in] Pointer to a Unicode string that contains the name of the computer where the action will take place. The local computer can be specified by setting this parameter to NULL.


[in] Pointer to a Unicode string that describes the type of object that will be worked on. Possible strings are:


Required to act upon the queue manager on the computer.


Required to act upon a specific queue on the computer.


[in] Pointer to a Unicode string that indicates the action to be performed on the computer.


Connects the computer to the network and to the directory service.


Disconnects the computer from the network and from the directory service.


Cleans up empty message files (Message Queuing cleans up empty message files every six hours). This is helpful when a large number of messages are deleted (purged or received by an application) and the application needs the disk space available at once.


Valid for outgoing queues only. Stops the sending of messages from the computer. The queue manager will not send messages to the applicable destination queue until a RESUME action is initiated.


Valid for outgoing queues only. Restarts the sending of messages after a PAUSE action has been initiated.


Resends the pending transaction sequence.


Indicates success.


The access rights for performing management actions on the queue or computer are not allowed for the calling process.


The specified format name in pObjectName is illegal.


The Message Queuing service is not available.

You can call MQMgmtAction with pAction = L"PAUSE" when you know that the corresponding destination queue is unavailable. This can reduce the unnecessary CPU and network load associated with repeated attempts to connect to the unavailable target.

Local administrative permissions are needed to change the state of a computer or a queue using MQMgmtAction.

The functionality of the local administration API functions introduced in MSMQ 3.0 (MQMgmtAction, MQMgmtGetInfo, and MQPurgeQueue) is also available for computers running previous versions of Message Queuing. For more information, see MSMQ Local Admin API.

Equivalent COM Methods

When using COM components, you can change the connection state of a computer and clean up the empty message files on a computer by calling the MSMQApplication.Connect, MSMQApplication.Disconnect, and MSMQApplication.Tidy methods of the MSMQApplication object. You can also stop and resume sending messages from an outgoing queue and resend the pending transaction sequence by calling the MSMQOutgoingQueueManagement.Pause, MSMQOutgoingQueueManagement.Resume, and MSMQOutgoingQueueManagement.EodResend methods of the MSMQOutgoingQueueManagement object.

Windows NT/2000/XP: Included in Windows XP and Windows Server 2003.

Windows 95/98/Me: Unsupported.

Header: Declared in Mq.h.

Library: Use Mqrt.lib.

Message Queuing Functions

Community Additions