System.Messaging.MessageQueue类不提供设置队列所有权的方法。如何以编程方式设置MSMQ消息队列的所有者?
答案 0 :(得分:4)
简短的回答是p /调用windows api函数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
上定义{{1}}扩展方法的完整类