How to set the owner of a message queue?

The System.Messaging.MessageQueue class does not provide a way to specify ownership of a queue. How to programmatically set the owner of an MSMQ message queue?

+3
source share
1 answer

Short answer: p / call the windows api function call 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(); } 

The full class that defines the SetOwner extension SetOwner on System.Messaging.MessageQueue can be found on github

+4
source

Source: https://habr.com/ru/post/1206640/


All Articles