简体   繁体   中英

Set MSMQ permissions using VBScript (via Nant)

We are using Nant to deploy an application and need to create some MSMQ Queues during the process.

We use Nant/psexec/cscript to call a VBScript to create the queue itself but we also need to set the permissions.

Can this be done programmatically?

I am aware of Setting permissions on a MSMQ queue in script however that question asks for PowerShell or VBScript and has an accepted answer for PowerShell. We do not have PowerShell available to us so this question is specific to VBScript.

Just came across this and saw that it was unanswered. The trick here is to use VB.Net or C# code directly in nAnt. You can do this with a nAnt include, with a script task in the global space; and in the code, derive from the Task class.

Or. you can put your script block in a target. I prefer the former method, since it is easier to reuse and pass in parameters.

In either case, this is NOT VBScript, it is fully compiled .Net code, so you can do pretty much anything.

In your code element, Import System.Messaging, and create the Queue in your ExecuteTask override. Don't forget to give read/write/peek permissions to .\\Users, or you probably don't be able to use the Queue properly except from the user that ran the nAnt script (which usually isn't the web server or Windows service that is reading the queue.)

Also, since you have full access to the Messaging.MessageQueue class, you can check for existence and delete an existing queue, or not!

According to this post , MSMQ scripting API doesn't provide any means to set permissions on queries, so this task cannot be accomplished using VBScript.

I can suggest the following workarounds:

  • Use PowerShell, as illustrated in the post you linked to. (PowerShell can use the .NET Framework and, therefore, the MSMQ .NET API provided by the System.Messaging assembly.)
  • Create a custom utility that would set the necessary permissions and call this utility as part of your deployment process. For setting the queue security, you can use the following API functions:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM