Esempio n. 1
0
        private void WalkMachineGroups()
        {
            IntPtr enumbuffer   = IntPtr.Zero;
            uint   entriesread  = 0;
            uint   totalentries = 0;

            uint rc = NetApi32.NetLocalGroupEnum(null, 0, ref enumbuffer, 0xFFFFFFFF, out entriesread, out totalentries, IntPtr.Zero);

            this.Success = (rc == 0);

            if (this.Success)
            {
                for (int cnt = 0; cnt < totalentries; cnt++)
                {
                    LOCALGROUP_INFO_0 ginfo = (LOCALGROUP_INFO_0)Marshal.PtrToStructure(enumbuffer, typeof(LOCALGROUP_INFO_0));

                    HandleLocalGroup(ginfo);

                    try
                    { enumbuffer = (IntPtr)((Int64)enumbuffer + Marshal.SizeOf(typeof(LOCALGROUP_INFO_0))); }

                    catch (Exception)
                    { break; }
                }

                NetApi32.NetApiBufferFree(enumbuffer);
            }
        }
Esempio n. 2
0
        private void HandleLocalGroup(LOCALGROUP_INFO_0 ginfo)
        {
            IntPtr enumbuffer   = IntPtr.Zero;
            uint   entriesread  = 0;
            uint   totalentries = 0;

            string sid = GetAccountSid(ginfo.lgrpi0_name);

            GroupInfo group = new GroupInfo(sid, ginfo.lgrpi0_name);

            uint rc = NetApi32.NetLocalGroupGetMembers(null, group.NTName, 1, ref enumbuffer, 0xFFFFFFFF, out entriesread, out totalentries, IntPtr.Zero);

            this.Success = (rc == 0);

            if (this.Success)
            {
                for (int cnt = 0; cnt < totalentries; cnt++)
                {
                    LOCALGROUP_MEMBERS_INFO_1 member = (LOCALGROUP_MEMBERS_INFO_1)Marshal.PtrToStructure(enumbuffer, typeof(LOCALGROUP_MEMBERS_INFO_1));

                    string msid = GetAccountSid(member.lgrmi1_sid);

                    SidInfo sinfo = new SidInfo(msid, member.lgrmi1_name, member.lgrmi1_sidusage);

                    group.Members.Add(sinfo);

                    group.SidList.Add(msid);

                    try
                    { enumbuffer = (IntPtr)((Int64)enumbuffer + Marshal.SizeOf(typeof(LOCALGROUP_MEMBERS_INFO_1))); }

                    catch (Exception)
                    { break; }
                }

                this.Groups.AddSafe(group);

                NetApi32.NetApiBufferFree(enumbuffer);
            }
        }