/// <summary>
        /// Converts a Discretionary Access Mask into WMIWinACE struct.
        /// </summary>
        /// <param name="bitwiseAccessMask">The source access mask as unassigned integer;</param>
        /// <returns>It returns a WMIWinACE struct with all object access rights calculated from Access Mask.</returns>
        public WMIWinACE GetSecurityDescriptorFromAccessMask(uint bitwiseAccessMask)
        {
            WMIWinACE result = new WMIWinACE()
            {
                AccessMask = bitwiseAccessMask
            };

            result.CalculateFileAccessRightsFromAccessMask();
            result.CalculateRegistryKeyAccessRightsFromAccessMask();

            return(result);
        }
        /// <summary>
        /// Creates a list of WinACEs objects from security descriptor management object.
        /// </summary>
        /// <param name="rootManagementObject">The result of invoked method which returns the Security Descriptor as ManagementBaseObject.</param>
        /// <param name="trusteeName">The username formatted such as: "[DOMAIN]\[USERNAME]". For local users use the machine name on [DOMAIN]</param>
        /// <returns>Returns a List of WMIWinACE objects.</returns>
        public virtual IEnumerable <WMIWinACE> GetAllSecurityDescriptorsFromManagementObject(object rootManagementObject)
        {
            var ACLs = this.getACLFromManagementObject((ManagementBaseObject)rootManagementObject);

            var result = new List <WMIWinACE>();

            foreach (var acl in ACLs)
            {
                var newWinACE = new WMIWinACE()
                {
                    AccessMask = this.getPropertyValueAsUnsiggnedInteger(acl, "AccessMask"),
                    AceFlags   = this.getPropertyValueAsUnsiggnedInteger(acl, "AceFlags"),
                    AceType    = this.getPropertyValueAsUnsiggnedInteger(acl, "AceType"),
                    Trustee    = this.getWinTrusteeFromManagementObject((ManagementBaseObject)acl.Properties["Trustee"].Value)
                };
                newWinACE.CalculateFileAccessRightsFromAccessMask();

                result.Add(newWinACE);
            }

            return(result);
        }
        /// <summary>
        /// Creates a list of WinACEs objects from security descriptor management object.
        /// </summary>
        /// <param name="rootManagementObject">The result of invoked method which returns the Security Descriptor as ManagementBaseObject.</param>
        /// <param name="trusteeName">The username formatted such as: "[DOMAIN]\[USERNAME]". For local users use the machine name on [DOMAIN]</param>
        /// <returns>Returns a List of WMIWinACE objects.</returns>
        public virtual IEnumerable <WMIWinACE> GetSecurityDescriptorsFromManagementObject(object rootManagementObject, string userTrusteeName, WmiDataProvider wmiProvider)
        {
            ManagementBaseObject[] ACLs = this.getACLFromManagementObject((ManagementBaseObject)rootManagementObject);

            var result = new List <WMIWinACE>();

            foreach (var acl in ACLs)
            {
                var aclTrustee = (ManagementBaseObject)acl.Properties["Trustee"].Value;
                if (this.DoesACLBelongToUser(aclTrustee, userTrusteeName, wmiProvider))
                {
                    WMIWinACE newWinACE = new WMIWinACE();
                    newWinACE.AccessMask = this.getPropertyValueAsUnsiggnedInteger(acl, "AccessMask");
                    newWinACE.AceFlags   = this.getPropertyValueAsUnsiggnedInteger(acl, "AceFlags");
                    newWinACE.AceType    = this.getPropertyValueAsUnsiggnedInteger(acl, "AceType");
                    newWinACE.Trustee    = this.getWinTrusteeFromManagementObject(aclTrustee);
                    newWinACE.CalculateFileAccessRightsFromAccessMask();

                    result.Add(newWinACE);
                }
            }

            return(result);
        }