public void TestLocalGroupDeleteByName() { NTHost host = NTHost.CurrentMachine; // find a unique user name NTLocalUser user = null; NTLocalGroup group = null; try { group = host.CreateLocalGroup(GenerateGroupName(host), null); user = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123"); group.AddLocalMember(user.Name); Assert.IsTrue(ContainsObjectByName(group.GetLocalMembers(), user.Name)); group.DeleteLocalMember(user.Name); CollectionAssert.IsEmpty(group.GetLocalMembers()); } finally { try { if (user != null) { user.Delete(); } } catch { } try { if (user != null) { group.Delete(); } } catch { } } }
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); }
public void TestLocalGroupEmptyMembers() { NTHost host = NTHost.CurrentMachine; // find a unique user name NTLocalGroup group = null; try { group = host.CreateLocalGroup(GenerateGroupName(host), "description"); CollectionAssert.IsEmpty(group.GetLocalMembers()); } finally { try { if (group != null) { group.Delete(); } } catch { } } }
public void TestLocalGroupWithMultipleMembersWithWithGroupMembershipVerify() { NTHost host = NTHost.CurrentMachine; // find a unique user name NTLocalUser user1 = null; NTLocalUser user2 = null; NTLocalGroup group1 = null; NTLocalGroup group2 = null; NTLocalGroup group3 = null; try { group1 = host.CreateLocalGroup(GenerateGroupName(host), "description"); Assert.IsNotNull(group1); group2 = host.CreateLocalGroup(GenerateGroupName(host), "description"); Assert.IsNotNull(group2); group3 = host.CreateLocalGroup(GenerateGroupName(host), "description"); Assert.IsNotNull(group3); user1 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123"); user2 = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123"); group1.AddLocalMember(user1.Name); group1.AddLocalMember(user2.Name); group2.AddLocalMember(user1.Name); group3.AddLocalMember(user2.Name); NTLocalObject[] group1Members = group1.GetLocalMembers(); Assert.IsNotNull(group1Members); Assert.AreEqual(2, group1Members.Length); Assert.IsTrue(ContainsObjectByName(group1Members, user1.Name)); Assert.IsTrue(ContainsObjectByName(group1Members, user2.Name)); NTLocalObject[] group2Members = group2.GetLocalMembers(); Assert.IsNotNull(group2Members); Assert.AreEqual(1, group2Members.Length); Assert.IsTrue(ContainsObjectByName(group2Members, user1.Name)); NTLocalObject[] group3Members = group3.GetLocalMembers(); Assert.IsNotNull(group3Members); Assert.AreEqual(1, group3Members.Length); Assert.IsTrue(ContainsObjectByName(group3Members, user2.Name)); } finally { try { if (user1 != null) { user1.Delete(); } } catch { } try { if (user2 != null) { user2.Delete(); } } catch { } try { if (group1 != null) { group1.Delete(); } } catch { } try { if (group2 != null) { group2.Delete(); } } catch { } try { if (group3 != null) { group3.Delete(); } } catch { } } }