Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically add private queues in MSMQ

I have list of over 20 queues that needs to be added as private queue in MSMQ.

Is there a way to do it using

  1. Command Line

  2. C# programming

If there is a way to do using some sort of script or .net programming then I could add it with out manually inputting it and causing typos.

Please let me know.

thanks

like image 652
irvinedotnet Avatar asked Apr 05 '11 22:04

irvinedotnet


2 Answers

using System.Messaging;

//...

void CreateQueue(string qname) {
   if (!MessageQueue.Exists(qname)) MessageQueue.Create(qname);
}

You can only create private queues on your local computer. For more information see: Creating Queues

like image 142
Richard Schneider Avatar answered Nov 19 '22 17:11

Richard Schneider


For command line, you can create a .vbs file with following content:

Option Explicit

Dim objInfo
Dim objQue
Dim objMsg
Dim strFormatName   ' Destination

strFormatName = "direct=os:.\private$\test"

Set objInfo = CreateObject("MSMQ.MSMQQueueInfo")
Set objMsg = CreateObject("MSMQ.MSMQMessage")

objMsg.Label = "my message"
objMsg.Body = "This is a sample message."
objInfo.FormatName = strFormatName
set objQue = objInfo.Open( 2, 0 )

' Send Message
objMsg.Send  objQue

' Close Destination
objQue.Close

Set objMsg = Nothing
Set objInfo = Nothing

msgbox "Done..."
like image 24
Zé Carlos Avatar answered Nov 19 '22 17:11

Zé Carlos