示例#1
0
        /// <summary>
        /// Gets the token's privileges.
        /// </summary>
        /// <returns>A TOKEN_PRIVILEGES structure.</returns>
        public Privilege[] GetPrivileges()
        {
            int retLen;

            Win32.GetTokenInformation(this, TokenInformationClass.TokenPrivileges, IntPtr.Zero, 0, out retLen);

            using (MemoryAlloc data = new MemoryAlloc(retLen))
            {
                if (!Win32.GetTokenInformation(this, TokenInformationClass.TokenPrivileges, data,
                                               data.Size, out retLen))
                {
                    Win32.Throw();
                }

                uint        count      = data.ReadUInt32(0);
                Privilege[] privileges = new Privilege[count];

                for (int i = 0; i < count; i++)
                {
                    var laa = data.ReadStruct <LuidAndAttributes>(sizeof(int), i);
                    privileges[i] = new Privilege(this, laa.Luid, laa.Attributes);
                }

                return(privileges);
            }
        }