【问题标题】:How do I set the owner of a message queue?如何设置消息队列的所有者?
【发布时间】:2012-07-01 13:18:16
【问题描述】:

System.Messaging.MessageQueue 类不提供设置队列所有权的方法。如何以编程方式设置 MSMQ 消息队列的所有者?

【问题讨论】:

    标签: c# msmq


    【解决方案1】:

    简短的回答是 p/invoke 调用 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();
    }
    

    System.Messaging.MessageQueue 上定义SetOwner 扩展方法的完整类可以在github 上找到

    【讨论】:

      猜你喜欢
      • 2017-11-17
      • 2013-03-24
      • 2010-11-19
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 2014-08-08
      相关资源
      最近更新 更多