Search code examples
c#msmq

C# Get MSMQ Messages in System Queues


So C# allows me to use GetPrivateQueues and GetPublicQueues but there is nothing to get System Queues. I have written this code

string deadLetterQueuePath = @"formatname:DIRECT=OS:.\system$;DeadLetter";

MessageQueue deadLetterQueue = new MessageQueue(deadLetterQueuePath);

Message[] messages = deadLetterQueue.GetAllMessages();

foreach (Message message in messages)
{
    Console.WriteLine(message.ToString());
    Console.ReadLine();
}

The code fails on the MessageQueue line. Here is the error I get

"The specified format name does not support the requested operation. For example, a direct queue format name cannot be deleted."

Could this just be a limitation of running this against my Windows 8 PC? Am I doing something wrong? Could this be a permission issue since the account I am using is not a local admin even when I can pull private and public queues?

Thank you


Solution

  • Something I answered in the old MSMQ newsgroups a while ago might help if it's a permissions problem.

    No Manual or Programmatic Access to Dead Letter or Any System Queue