I created a script to monitor a set of queues, and, while it works perfectly with Remote Private Queues, it doesn't work with Outgoing Queues. I made an experiment by removing everything but the essential from the script, and I created the following test script:
var info = new ActiveXObject("MSMQ.MSMQQueueInfo");
info.FormatName = /*<Queue name>*/;
// 0x80 = MQ_ADMIN_ACCESS
// 0x20 = MQ_PEEK_ACCESS
// 0x00 = MQ_DENY NONE
var mq = info.Open(0x80 | 0x20, 0x00);
var msg = mq.PeekCurrent(false, true, 0);
if (msg != null) {
WScript.echo("message found");
}
else
{
WScript.echo("Nothing");
}
mq.close();
I then ran it on the server and, even if the queue contains over a thousand messages, PeekCurrent always returns null. If I remove MQ_ADMIN_ACCESS it tries to connect to the Remote Private Queue and it times out (as expected, as it's down to let messages cumulate). If I then start the Remote Private Queue, it reads the message correctly from it.
Out of curiosity, I found out that info.Open always succeeds no matter the Queue Name (i.e. whether it exists or not) when MQ_ADMIN_ACCESS is used. For example, I typed "DIRECT=OS:Whatever\private$\RandomQueueName", and I didn't get any error.
I'm not an expert of MSMQ (quite the opposite), so I'm probably making an obvious mistake and I can't see it. Any help is more than welcome. Thanks.
Side question: is it possible to peek a Remote Outgoing Queue? At the moment the script is running on the machine where the Outgoing Queue I'm testing is located, but it's not the only one with these queues. I'd like to avoid deploying the script everywhere, I'd prefer to have it in a single place. Thanks.