VBScript Code Example: Opening a Queue

 

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

To open a queue you must set the queue's access mode and its share mode. This example opens a queue to send messages. The queue's access and share modes are set to MQ_SEND_ACCESS and MQ_DENY_NONE, respectively.

System_CAPS_ICON_important.jpg Important

In VBScript, the numerical values of the constants must be used. (This example can be modified to peek at or retrieve messages by changing the access and share modes accordingly.)

System_CAPS_ICON_note.jpg Note

Remote queues can be opened to send messages while offline. To do this, your application must either obtain and cache the format name of the remote queues while online, or your application must have the information needed to construct a direct format name for the queue.

The initial properties of an opened queue are based on the properties of the MSMQQueueInfo object used to open the queue. You can always obtain these initial settings, even if the open queue's properties are changed, by looking at the queue's MSMQQueue.QueueInfo property.

The following procedure lists the steps for opening a known queue to send messages and close the queue (the code for sending messages is not included).

To open a queue to send messages

  1. Declare an MSMQQueueInfo and MSMQQueue object.

  2. Obtain an MSMQQueueInfo object. (The following example tries to create a new MSMQQueueInfo object using a known path name. If the queue already exists, the example ignores the error and uses the existing queue.)

System_CAPS_ICON_note.jpg Note

You can also obtain MSMQQueueInfo objects for public queues by calling MSMQQuery.LookupQueue to query the directory service.

  1. Call MSMQQueueInfo.Open to open the queue with send access. The following example sets the access mode to 2 (MQ_SEND_ACCESS) and the share mode to 0 (MQ_DENY_NONE).

  2. Add your code to send messages.

  3. Call MSMQQueue.Close to close the queue.

The following example opens a public queue with send access. The queue is opened on the server computer with Active Server Pages and VBSript.

To run this example, paste the following code into a text file that has an .asp extension (for example, mq.asp), and then place the file in the InetPub\Scripts folder on your Web server. (If you use another folder, make sure that folder has execute script privileges.) You can then run this script from your Internet browser by referring to the address: http://<webservername>/scripts.mq.asp.

This example can be run on computers using any version of MSMQ. There are no version-specific components needed for this example.

<HTML>  
<BODY>  
<H1>Opening a public queue on a Web server</H1>  
<%  
    Set qinfo = Server.CreateObject ("MSMQ.MSMQQueueInfo")  
    qinfo.PathName = ".\TestQueue"  
    qinfo.Label = "Test Queue"  
    On Error Resume Next      'Disregard this error if the queue exists.  
    qinfo.Create  
    On Error Goto 0  
    Set qPub = qinfo.Open (2, 0)  
  
%>  
</BODY>  
</HTML>  

Community Additions

ADD
Show: