0

We have a public queue called .\publicQueue Error.

                    MessageQueue currentQueue = new MessageQueue(queue);
                    AccessControlList accessList = new AccessControlList();
                    Trustee queueOwner = new Trustee(user, Environment.MachineName, TrusteeType.User);
                    MessageQueueAccessControlEntry accessOwner = new MessageQueueAccessControlEntry(queueOwner, rights);
                    accessList.Add(accessOwner);

                    currentQueue.SetPermissions(accessList);

After executing the code I am presented with the following error: System.Messaging.MessageQueueException (0x80004005): Access to Message Queuing system is denied.

I can confirm that the queue does exist.

Any ideas of what might be wrong here?

I have found a suggestion saying that anonymous app pool creds can cause the issue, but this is not the case. The app pool is executing as the same user used as queueowner in the code.

p0enkie
  • 665
  • 2
  • 11
  • 22
  • I haven't used the MSMQ API in a couple of years, but I feel like there's another step before you can set permissions on the queue? If you think it's an execution context related issue. You can try executing as the QueueOwner explicitly using an impersonation context, see [this answer](https://stackoverflow.com/a/125356/) for more info – Arman Peiravi Jun 27 '17 at 16:27
  • duplicate: https://stackoverflow.com/questions/3731627/win-service-getting-permission-denied-to-message-queuing – SQLMason Jun 27 '17 at 18:19

1 Answers1

0

I solved this by incorporating the following code example to actaully set the owner before assigning rights :https://github.com/gavacho/System.Messaging.MessageQueue.SetOwner/blob/master/System.Messaging.MessageQueue.SetOwner.cs

p0enkie
  • 665
  • 2
  • 11
  • 22