Delen via


Visual Basic Code Example: Setting MSMQQueueInfo.BasePriority

 

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

This example provides a private Sub procedure that sets the MSMQQueueInfo.BasePriority property of an existing public queue based on a given base priority level.

Setting this property changes how Message Queuing routes new messages sent to the queue. Setting this property has no effect on messages already in the queue.

When Message Queuing updates the properties of a public queue, their values are stored in the directory service.

To set MSMQQueueInfo.BasePriority

  1. Declare the objects needed to update queue properties. This procedure declares an MSMQQueueInfo object.

  2. Create the MSMQQueueInfo object. This example then uses MSMQQueueInfo.PathName to set the path name to the string passed to the function.

  3. Optional. Call MSMQQueueInfo.Refresh to obtain the current registered settings of the queue properties. Note that this call retrieves any changes made by other applications.

  4. Set the MSMQQueueInfo.BasePriority property.

  5. Call MSMQQueueInfo.Update to register the new settings.

Code Example

The following code example can be run on all versions of Message Queuing.

Sub SetBasePriority( _  
                    strPathname As String, _  
                    lPriority As Long _  
                    )  
  Dim qinfo As MSMQQueueInfo  
  
  ' Create the MSMQQueueInfo object.  
  Set qinfo = New MSMQQueueInfo  
  qinfo.PathName = strPathname  
  On Error GoTo ErrorHandler  
  
  ' Retrieve the internally registered property values.  
  qinfo.Refresh  
  
  ' Set the new base priority in the MSMQQueueInfo object.  
  qinfo.BasePriority = lPriority  
  
  ' Update the internally registered property values.  
  qinfo.Update  
  
  MsgBox "A new queue base priority was set."  
  Exit Sub  
  
ErrorHandler:  
  MsgBox "Error " + Hex(Err.Number) + " was returned." _  
          + Chr(13) + Err.Description  
End Sub