Пример #1
0
        private void DecodePrivileges()
        {
            IntPtr ipprivs = TGP.Privileges;

            for (int privcnt = 1; privcnt <= TGP.PrivilegeCount; privcnt++)
            {
                LUID_AND_ATTRIBUTES la = (LUID_AND_ATTRIBUTES)Marshal.PtrToStructure(ipprivs, typeof(LUID_AND_ATTRIBUTES));

                PrivilegeInfo pinfo = new PrivilegeInfo(privcnt, la);

                Privileges.AddSafe(pinfo);

                PrivilegesStringList.AddSafe(pinfo.Name);

                try
                {
                    ipprivs = (IntPtr)((Int64)ipprivs + Marshal.SizeOf(typeof(LUID_AND_ATTRIBUTES)));
                }

                catch (Exception)
                { break; }
            }
        }
Пример #2
0
        public PrivilegeInfo(int pos, LUID_AND_ATTRIBUTES la)
        {
            Position = pos;

            Attributes = (PRIVILEGE_ATTRIBUTE_INFORMATION)la.Attributes;

            StringBuilder privname = new StringBuilder();

            IntPtr ipluid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LUID)));

            Marshal.StructureToPtr(la.Luid, ipluid, false);

            int cap = 0;

            Advapi32.LookupPrivilegeName(null, ipluid, privname, ref cap);

            privname.EnsureCapacity(cap);

            Advapi32.LookupPrivilegeName(null, ipluid, privname, ref cap);

            Marshal.FreeHGlobal(ipluid);

            Name = privname.ToString();
        }