[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Re: MessageQueue.Receive access denied -- solved

Klaus H. Probst

6/30/2004 11:20:00 PM

You could have also taken ownership of the queue.


--
Klaus H. Probst, MVP
http://www....


"pl_dave" <pldave@discussions.microsoft.com> wrote in message
news:7441DEF7-3F88-4257-9971-8121E7BBAEA4@microsoft.com...
> the problem was that the queue was created by a service that i wrote.
since that service was not running under my account, i was not the creator
of the queue. even as administrator, i didn't have authority to read or
delete the queue. so to solve the problem, i made the service delete the
queue and then recreated it by using the computer management console. now
it's all working fine.
>
> "pl_dave" wrote:
>
> > i wrote a simple app that creates and uses a private message queue. the
Send completes without errors, however when i call Receive i always get a
message queue exception saying access denied. the CanRead property is
false.
> >
> > the messagequeue constructor does not ask for exclusive access. there
is no other program using this private queue. the server explorer gets the
same error if i browse to the private queue.
> >
> > this is running on an XP pro platform under an administrator account.
there is a lot of stuff installed for development, but no special security
settings.
> >
> > any ideas about what's causing this? thanks!


2 Answers

(Shell D00d)

7/22/2004 2:10:00 AM

0

Hi,

I've noticed the same problem when creating a queue programatically in
both XP and 2k, but only on some machines. I'm not sure... I think it
has something to do with security policy or something.

Anyway, I sort of solved the problem by setting the security
permissions on the queue manually while creating the queue. Not a very
elegant solution, but it served my purpose at the time:

using System.Messaging;

AccessControlList acl = new AccessControlList();

Trustee trustee = new Trustee("SYSTEM", Environment.MachineName,
System.Messaging.TrusteeType.Group);

Trustee owner = new Trustee(System.Security.Principal.WindowsIdentity.GetCurrent().Name,
Environment.MachineName, System.Messaging.TrusteeType.User);

MessageQueueAccessControlEntry aceSystem = new
System.Messaging.MessageQueueAccessControlEntry(trustee,
System.Messaging.MessageQueueAccessRights.FullControl);

MessageQueueAccessControlEntry aceOwner = new
System.Messaging.MessageQueueAccessControlEntry(owner,
System.Messaging.MessageQueueAccessRights.FullControl);

acl.Add(aceSystem);
acl.Add(aceOwner);

myQueue.Permissions = acl;

(Shell D00d)

7/22/2004 2:10:00 AM

0

"pl_dave" <pldave@discussions.microsoft.com> wrote in message news:<7441DEF7-3F88-4257-9971-8121E7BBAEA4@microsoft.com>...
> the problem was that the queue was created by a service that i wrote. since that service was not running under my account, i was not the creator of the queue. even as administrator, i didn't have authority to read or delete the queue. so to solve the problem, i made the service delete the queue and then recreated it by using the computer management console. now it's all working fine.

Hi,

I've just posted code that allows the current user to access the
queue. However, I posted it under your previous post as I hadn't seen
this one! (silly me). Here it is again, anyway:

using System.Messaging;

AccessControlList acl = new AccessControlList();
Trustee trustee = new Trustee("SYSTEM", Environment.MachineName,
System.Messaging.TrusteeType.Group);
Trustee owner = new Trustee(System.Security.Principal.WindowsIdentity.GetCurrent().Name,
Environment.MachineName, System.Messaging.TrusteeType.User);
MessageQueueAccessControlEntry aceSystem = new
System.Messaging.MessageQueueAccessControlEntry(trustee,
System.Messaging.MessageQueueAccessRights.FullControl);
MessageQueueAccessControlEntry aceOwner = new
System.Messaging.MessageQueueAccessControlEntry(owner,
System.Messaging.MessageQueueAccessRights.FullControl);

acl.Add(aceSystem);
acl.Add(aceOwner);

myQueue.Permissions = acl;