Sending private messages requires setting the privacy level of the message, and, as an option, setting the privacy level of the queue where the message is sent before the message is sent.
The properties used to set the privacy level of the message are the MSMQMessage object's PrivLevel and EncryptAlgorithm properties. The property used to set the privacy level of the queue is the MSMQQueueInfo object's PrivLevel property.
The actual call to send and read private messages is the same as the call to send and read non-private messages.
Note Each MSMQ message can have no more than 4 MB of data.
qinfo.PrivLevel = MQ_PRIV_LEVEL_BODY
Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY
msg.EncryptAlgorithm = MQMSG_CALG_RC4
msg.Send q
Dim qinfo As New MSMQQueueInfo
Dim q As New MSMQQueue
Dim msg As New MSMQMessage
Private Sub Form_Click()
'**********************
' Create queue
'**********************
Set qinfo = New MSMQQueueInfo
qinfo.PathName = ".\PrivacyTest"
qinfo.Label = "Test Queue"
qinfo.PrivLevel = MQ_PRIV_LEVEL_BODY
qinfo.Create
'*********************
' Open queue.
'*********************
Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
'*********************
' Send message.
'*********************
msg.Label = "Test Message"
msg.Body = "This is a private message."
msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY
msg.EncryptAlgorithm = MQMSG_CALG_RC4
msg.Send q
MsgBox "The message " + msg.Label + " was sent."
q.Close
'*********************
' Receive message.
'*********************
Set q = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
Set msg = q.Receive
If msg.PrivLevel = MQMSG_PRIV_LEVEL_BODY Then
MsgBox "Message " + msg.Label + " is private."
Else
MsgBox "Message " + msg.Label + " is not private."
End If
MsgBox "Encryption alogithm is: " + CStr(msg.EncryptAlgorithm)
End Sub