public static DomainMachine[] FindMachine(string MachineName) { ArrayList ReturnValue = new ArrayList(); DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE"); string domain = (string)entryRoot.Properties["defaultNamingContext"][0]; DirectoryEntry entryDomain = new DirectoryEntry("LDAP://" + domain); using (DirectorySearcher searcher = new DirectorySearcher(entryDomain)) { searcher.ReferralChasing = ReferralChasingOption.All; searcher.SearchScope = SearchScope.Subtree; searcher.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn=" + MachineName + "))"; SearchResultCollection resultCol = searcher.FindAll(); if (resultCol != null) { for (int counter = 0; counter < resultCol.Count; counter++) { SearchResult result = resultCol[counter]; if (result.Properties.Contains("cn")) { DomainMachine Dm = new DomainMachine((String)result.Properties["cn"][0], result.Path); ReturnValue.Add(Dm); } } } } return((DomainMachine[])ReturnValue.ToArray(typeof(DomainMachine))); }
private void OKButton_Click(object sender, RoutedEventArgs e) { if (MachineItems.SelectedItem is DomainMachine) { DomainMachine SelectedItem = (DomainMachine)MachineItems.SelectedItem; SelectedOU = SelectedItem.Path; } ReturnValue = RETURN_OK; this.Close(); }