public void Clear() { Results.Clear(); LocalAdmins.Clear(); Persons.Clear(); Server = ""; }
private void GetLocalAdminsistrators(string server) { using (DirectoryEntry localAdminsistrators = new DirectoryEntry(String.Format("WinNT://{0}", server)).Children.Find("Administrators", "group")) { object localAdminMembers = localAdminsistrators.Invoke("members", null); foreach (object localAdminObject in (IEnumerable)localAdminMembers) { string[] properties = new string[7]; using (DirectoryEntry localAdminMember = new DirectoryEntry(localAdminObject)) { string[] adsPath = localAdminMember.InvokeGet("Adspath").ToString().Split('/'); string type = localAdminMember.InvokeGet("Class").ToString(); string account = adsPath[adsPath.Length - 1]; properties[(int)DC.SAM_ACCOUNT] = Server; properties[(int)DC.OBJECT_SID] = new SecurityIdentifier((byte[])localAdminMember.Properties["objectSid"].Value, 0).ToString(); properties[(int)DC.SAM_ACCOUNT] = account; properties[(int)DC.DISTINGUISHED_NAME] = ""; properties[(int)DC.STATUS] = ""; properties[(int)DC.SOURCE] = Server; if (adsPath.Length > 4 && type.ToLower() == "user") { properties[(int)DC.OBJECT_TYPE] = "localuser"; } else if (adsPath.Length > 4 && type.ToLower() == "group") { properties[(int)DC.OBJECT_TYPE] = "localgroup"; } else if (type.ToLower() == "user") { properties[(int)DC.OBJECT_TYPE] = "aduser"; } else if (type.ToLower() == "group") { properties[(int)DC.OBJECT_TYPE] = "adgroup"; } } LocalAdmins.Add(properties); } } }