问题
I try this: MessageQueue mq = new MessageQueue(".\Journal$"); mq.Purge();
It work good on XP. But, on windows 2003 server, I always have this error : "A workgroup installation computer does not support the operation."
回答1:
Try using format name like so:
MessageQueue mq = new MessageQueue("DIRECT=OS:computername\SYSTEM$;JOURNAL");
mq.Purge();
I think that system queue can't be access by path. You have to use format name.
look at Yoel Arnon's comment at the bottom of the page.
回答2:
The correct format for system queues:
FormatName:Direct=os:.\\System$;JOURNAL
I've tested this format on Windows 7 and Windows 2003.
(the dot after os: means the localhost/local computer)
var systemJournalQueue = new MessageQueue("FormatName:Direct=os:.\\System$;JOURNAL");
var systemDeadLetterQueue = new MessageQueue("FormatName:Direct=os:.\\System$;DEADLETTER");
var systemDeadXLetterQueue =new MessageQueue("FormatName:Direct=os:.\\System$;DEADXACT"));
systemJournalQueue.Purge();
or if you want to keep N days of messages you can do this:
private static void PurgeQueues(int archiveAfterHowManyDays, MessageQueue queue)
{
queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(System.String) });
queue.MessageReadPropertyFilter.ArrivedTime = true;
using (MessageEnumerator messageReader = queue.GetMessageEnumerator2())
{
while (messageReader.MoveNext())
{
Message m = messageReader.Current;
if (m.ArrivedTime.AddDays(archiveAfterHowManyDays) < DateTime.Now)
{
queue.ReceiveById(m.Id);
}
}
}
}
来源:https://stackoverflow.com/questions/1131384/how-to-purge-msmq-system-queue-journal-programmatically-on-a-workgroup-installat