如何设置一个消息队列的主人? [英] How do I set the owner of a message queue?
本文介绍了如何设置一个消息队列的主人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
的System.Messaging.MessageQueue类不提供一种方式来设置队列的所有权。我如何编程设置MSMQ消息队列的主人?
The System.Messaging.MessageQueue class does not provide a way to set ownership of queue. How do I programmatically set the owner of a MSMQ message queue?
推荐答案
简短的回答是P /调用到呼叫Windows API函数 MQSetQueueSecurity
The short answer is to p/invoke a call to the windows api function MQSetQueueSecurity
void SetOwner(MessageQueue queue, byte[] sid, bool ownerDefaulted = false)
{
var securityDescriptor = new Win32.SECURITY_DESCRIPTOR();
if (!Win32.InitializeSecurityDescriptor(securityDescriptor, Win32.SECURITY_DESCRIPTOR_REVISION))
throw new Win32Exception();
if (!Win32.SetSecurityDescriptorOwner(securityDescriptor, sid, ownerDefaulted))
throw new Win32Exception();
if (Win32.MQSetQueueSecurity(queue.FormatName, Win32.OWNER_SECURITY_INFORMATION, securityDescriptor))
throw new Win32Exception();
}
一个完整的类,它定义了一个 SetOwner
在 System.Messaging.MessageQueue
可以的 github上
A complete class which defines a SetOwner
extension method on System.Messaging.MessageQueue
can be found on github
这篇关于如何设置一个消息队列的主人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文