How can I automate the creation of a MSMQ message queue?

3

2

I need to create many message queues (MSMQ) on a regular basis, so I want to automate the process. I'd prefer to use bat, but I'm plenty open to other ideas too. Unfortunately, I'm unable to find any information on how to do this. All of my searching returns results about pkgmgr.exe and installing MSMQ. Nothing about actually creating a queue.

For reference, I'll be using this on Windows 7 and Server 2008R2. Any ideas?

Lodra

Posted 2012-08-24T18:04:56.610

Reputation: 65

Hi Lodra, I was wondering if you had any feedback, positive or negative, on my proposed solution? – dsolimano – 2012-10-17T13:34:11.657

Answers

3

If you're open to PowerShell, you have access to all of the System.Messaging classes in the .Net framework. I believe modern versions of Windows come with PowerShell as part of the operating system, at least according to Wikipedia:

PowerShell v2.0 was completed and released to manufacturing in August 2009, as an integral part of Windows 7 and Windows Server 2008 R2.

This StackOverflow question, for example, while about setting permissions on a queue, also has an example of creating a queue.

Write-Host "... create a new queue"
$q1 = [System.Messaging.MessageQueue]::Create(".\private$\MyQueue")

Write-Host "... create new queue, set FullControl permissions for RBC\BIZTALK"
$qb = [System.Messaging.MessageQueue]::Create(".\private$\BtsQueue")

$qb.SetPermissions("RBC\BIZTALK", 
      [System.Messaging.MessageQueueAccessRights]::FullControl,            
      [System.Messaging.AccessControlEntryType]::Set)

I'm not sure what basis you're using to create your queues, but if you're parsing a text file with one queue name per line or something similar, it is quite easy to read it in and create queues based on the text file.

Another useful link might be this SU question, which is about deleting queues from VBScript. I'm not familiar enough with the MSMQApplication object that is being referenced, but presumably if queues can be deleted, they can be created.

dsolimano

Posted 2012-08-24T18:04:56.610

Reputation: 2 778

I completely forgot about this. Very late on my part but this worked great for me. Upvote – Lodra – 2013-10-07T15:49:04.360

Huh, I forgot about it too. Glad to be of assistance. – dsolimano – 2013-10-07T18:00:33.160