tags:

views:

279

answers:

1

Is it possible to delete a private message queue that was created by the service user? During uninstallation, we would like to clean up any message queues created by our application. For security purposes, access to these queues has been restricted to the current user (ServiceUser). During uninstall, we have admin privileges, but still get an access denied MessageQueueException when we attempt to delete the queue or modify the privs on the queue.

Here is the cleanup code:

    public void DeleteAppQueues()
    {
        List<string> trash = new List<string>();

        var machineQueues = MessageQueue.GetPrivateQueuesByMachine(".");
        foreach (var q in machineQueues)
        {
            if (IsAppQueue(q.QueueName))
            {
                trash.Add(".\\" + q.QueueName);
            }
            q.Dispose();
        }

        foreach (var queueName in trash)
        {
            try
            {
                using (MessageQueue delQueue = new MessageQueue(queueName))
                {
                    delQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl, AccessControlEntryType.Allow);
                }
                MessageQueue.Delete(queueName);
            }
            catch (MessageQueueException ex)
            {
                // ex.Message is "Access to Message Queuing system is denied."
            }                
        }
    }
A: 

Being administrator is not enough. You have to have the "Delete" permission. And before that you have to have the "Set Permission" right( or be the queue owner) to set the permissions.

Is the exception thrown on the "SetPermissions" call or on the "Delete" call?

Igal Serban
Both the delete call and the SetPermissions calls throw.
Todd Kobus