title: How to programmatically set Permission settings on private MSMQ queue for remote access?
body: <p>As part of an application I'm developing, Im trying to make use of Microsoft Message Queueing functionality and im having trouble with permission settings.</p>
  
  <p>I want to create a queue and send messages to it on a server computer and access it from a client computer over the local network. Both computers (both Windows 7 Home Premium) are on the same LAN network and are able to ping to each other. I will know the exact path of the created queue, so I guess private queues are ok. </p>
  
  <p>Im basing my code on <a href="http://www.ironpython.info/index.php/Message_Queuing" rel="nofollow">this example</a>  and use IronPython to access the <a href="http://msdn.microsoft.com/en-US/library/system.messaging.messagequeue%28v=vs.80%29" rel="nofollow">MessageQueue class</a> from the System.Messaging namespace. The send &amp; receive setup from the example works to create a queue and send it a message in one console:</p>
  
  <pre><code>&gt;&gt;&gt; localQueue = MessageQueue.Create('.\\private$\\testQueue')
  &gt;&gt;&gt; localQueue.FormatName
  'DIRECT=OS:&lt;clientMachineName&gt;\\private$\\testQueue'
  &gt;&gt;&gt; localQueue.Send('hello from other console')
  </code></pre>
  
  <p>and then access the queue and peek at it in another console by the following code:</p>
  
  <pre><code>&gt;&gt;&gt; SemiRemoteQueue = MessageQueue('FormatName:Direct=OS:&lt;clientMachineName&gt;\\private$\\testQueue')
  &gt;&gt;&gt; SemiRemoteQueue.Peek()
  &lt;System.Messaging.Message object at 0x000000000000002F [System.Messaging.Message
  ]&gt;
  </code></pre>
  
  <p>When I create a new queue on the server computer, I seem to be able to establish a connection from the client computer, but fail to get any message data from it. Peeking from client to queue created at server, gives the following 'Access denied' error message:</p>
  
  <pre><code>&gt;&gt;&gt; ReallyRemoteQueue = MessageQueue('FormatName:Direct=OS:&lt;serverMachineName&gt;\\private$\\remoteTestQueue')
  &gt;&gt;&gt; ReallyRemoteQueue.Peek()
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  EnvironmentError: System.Messaging.MessageQueueException (0x80004005): Access to
   Message Queuing system is denied.
     at System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
     at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int3
  2 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback rece
  iveCallback, CursorHandle cursorHandle, IntPtr transaction)
     at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 actio
  n, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction in
  ternalTransaction, MessageQueueTransactionType transactionType)
     at System.Messaging.MessageQueue.Peek()
     at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame
   frame)
     at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
     at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T
  1 arg1, T2 arg2)
     at IronPython.Compiler.Ast.CallExpression.Invoke0Instruction.Run(InterpretedF
  rame frame)
     at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
     at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 a
  rg1)
     at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
     at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
     at IronPython.Hosting.PythonCommandLine.&lt;&gt;c__DisplayClass1.&lt;RunOneInteraction
  &gt;b__0()
  </code></pre>
  
  <p>I've found that accessing remote private MSMQ queues should be possible, but can't figure out how to set the right permissions. I have allowed MSMQ in Firewall settings and even tried with firewall turned off. Found some discussion about applying permission settings to queue files but this doesn't help as I dont have queue files that have the security settings working for them. I haven't gotten round trying the option of given full access to 'Anonymous Logon' as has been suggested, but would eventually like to set permissions programmatically (in code), not in files' context menus. Should I use the SetPermissions method in the MessageQueing Class (http://msdn.microsoft.com/en-us/library/dd48yz36(v=vs.80))? How do I specify its parameters?</p>
  
  <p>Thanks for any suggestions!</p>