Ejemplo n.º 1
0
        public void TestLocalGroupCreateDelete()
        {
            NTHost       host      = NTHost.CurrentMachine;
            string       groupName = GenerateGroupName(host);
            NTLocalGroup group     = host.CreateLocalGroup(groupName, null);

            Assert.IsNotNull(group);
            Assert.IsTrue(ContainsObjectByName(host.GetLocalGroups(), groupName));
            group.Delete();
            Assert.IsFalse(ContainsObjectByName(host.GetLocalGroups(), groupName));
        }
Ejemplo n.º 2
0
        public void TestLocalHostGetAdministratorsGroup()
        {
            NTHost host = NTHost.CurrentMachine;

            NTLocalGroup[]     localGroups  = host.GetLocalGroups();
            NTLocalGroup       group        = GetObjectByName(localGroups, "Administrators");
            SecurityIdentifier localHostSid = host.SID;
            SecurityIdentifier adminSid     = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, localHostSid);

            Assert.IsTrue(
                ContainsSid(
                    adminSid,
                    host.GetLocalGroups()
                    )
                );
        }
Ejemplo n.º 3
0
        private string GenerateGroupName(NTHost host)
        {
            string groupName = "_TmpGrp";

            while (ContainsObjectByName(host.GetLocalGroups(), groupName))
            {
                groupName = "_TmpGrp" + Guid.NewGuid().ToString().Substring(0, 4);
            }
            return(groupName);
        }
Ejemplo n.º 4
0
        public void TestLocalHostGetPowerUsersGroup()
        {
            NTHost host = NTHost.CurrentMachine;

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.BuiltinPowerUsersSid, null),
                    host.GetLocalGroups()
                    )
                );
        }
Ejemplo n.º 5
0
        public void TestRemoteHostGetPowerUsersGroup()
        {
            NTHost host = new NTHost(RemoteHostName);

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.BuiltinPowerUsersSid, null),
                    host.GetLocalGroups()
                    )
                );
        }
Ejemplo n.º 6
0
        public void TestRemoteHostGetAdministratorsGroupMembers()
        {
            NTHost host = new NTHost(RemoteHostName);

            NTLocalGroup[] localGroups = host.GetLocalGroups();
            NTLocalGroup   group       = GetObjectByName(localGroups, "Administrators");

            NTLocalObject[] members = group.GetLocalMembers();
            Assert.IsNotNull(members);
            CollectionAssert.IsNotEmpty(members);
        }
Ejemplo n.º 7
0
        public void TestLocalGroupGetDescription()
        {
            NTHost       host        = NTHost.CurrentMachine;
            string       groupName   = GenerateGroupName(host);
            string       description = "Test description";
            NTLocalGroup group       = host.CreateLocalGroup(groupName, description);

            try {
                group = GetObjectByName(host.GetLocalGroups(), groupName);
                Assert.AreEqual(description, group.Description);
            } finally {
                group.Delete();
            }
        }