问题
On an XP machine there is a private messagequeue that was created by a .net service. When I want to access this private queue in a VB6 application I keep getting an "Access is denied" error. So it seems this is a security issue, only I don't understand why even when I am logged on as an administrator I still can't have access to queue that was created on the same machine. Is there something else I have to take into account.
Sample on how I use the queue in VB6
Public msgQueue As MSMQQueue
Private Sub OpenQueue()
Dim MQ As New MSMQQueueInfo
MQ .PathName = ".\Private$\incommingQueue"
Set msgQueue = MQ.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
End Sub
回答1:
This can happen if the .NET Service removed the "Everyone" group from the permissions the private queue. Here are some steps you can take to resolve this:
Stop the MSMQ Service
Open the folder
C:\WINDOWS\system32\msmq\storage\lqs
Find the file in this folder that describes your queue -- (incommingQueue)
Using notepad, open the lqs file for some other private queue that has good security permissions. (If you don't have any other private queues create one)
Locate the line in the file that begins
Security=....
Copy the whole line to your clipboard (watch out for Word Wrap, this line will be quite long)
Open the lqs file for your problem queue in your text editor
Overwrite the
Security=...
line in this file with the contents of your clipboardSave the modified lqs file
Start the MSMQ service
You should find that the problem queue now has the same permissions as the queue whose security settings you copied at step 6 above.
回答2:
The solution posted here seems a bit of a hack. Perhaps this is necessary for Windows XP. I've encountered something similar using Windows 7 and used a different approach to solve this.
Situation:
- Program consists of C# code that creates a private transactional queue
- Program is run as a windows service, running on the Local System account.
- When the service is run, the private queue is created with the Local System account as the owner.
- Even though I am administrator, I can't inspect the messages from the queue.
Solution (this is for Windows 7):
- Run compmgmt.msc
- Open 'Services and Applications'
- Open 'Message Queues'
- Open 'Private Queues'
- Right-click the newly created queue
- Click 'Properties'
- Select the 'Security' tab
- Click 'Advanced'
- Select the 'Owner' tab
- Select 'Administrator'
- Select 'Permissions' tab
- Click 'Add'
- Type in the name of you account (e.g. 'Administrator')
- Click 'Check names'
- Click 'OK'
- Click 'OK'
- Click 'OK'
Now you can access the messages in the queue and also purge the queue if you would like to.
来源:https://stackoverflow.com/questions/781154/no-permission-to-access-a-private-msmq