public virtual DialogResult ShowDirectoryObjectPickerDialog(IWin32Window parentWindow) { try { return(_directoryObjectPicker.ShowDialog(parentWindow)); } catch (Exception e) { var popupController = CustomContainer.Get <Common.Interfaces.Studio.Controller.IPopupController>(); if (popupController != null) { var popupMessage = new PopupMessage { Description = Core.Error_Opening_Windows_Group_Picker, Image = MessageBoxImage.Error, Buttons = MessageBoxButton.OK, IsError = true, Header = @"Error" }; popupController.Show(popupMessage); } Dev2Logger.Error(@"Error opening group picker: ", e); } return(DialogResult.Cancel); }
public static async Task <string> OpenObjectPicker(long hwnd) { return(await Win32API.StartSTATask(() => { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog() { AllowedObjectTypes = ObjectTypes.All, DefaultObjectTypes = ObjectTypes.Users | ObjectTypes.Groups, AllowedLocations = Locations.All, DefaultLocations = Locations.LocalComputer, MultiSelect = false, ShowAdvancedView = true }; picker.AttributesToFetch.Add("objectSid"); using (picker) { if (picker.ShowDialog(Win32API.Win32Window.FromLong(hwnd)) == DialogResult.OK) { try { var attribs = picker.SelectedObject.FetchedAttributes; if (attribs.Any() && attribs[0] is byte[] objectSid) { return new SecurityIdentifier(objectSid, 0).Value; } } catch { } } } return null; })); }
private void llBrowseAdmUser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog() { AllowedObjectTypes = ObjectTypes.Users, DefaultObjectTypes = ObjectTypes.Users, AllowedLocations = Locations.All, DefaultLocations = Locations.JoinedDomain, MultiSelect = false, ShowAdvancedView = true, AttributesToFetch = { "samAccountName" } }; if (picker.ShowDialog() == DialogResult.OK) { DirectoryObject sel = picker.SelectedObjects.FirstOrDefault(); string userName = sel?.FetchedAttributes.FirstOrDefault() as string; if (sel != null) { if (txtStdUser.Text != userName) { txtAdmUser.Text = userName; } else { MetroMessageBox.Show(this, "Username already in use", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
private void BrowseBTN_Click(object sender, EventArgs e) { try { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog(); picker.AllowedObjectTypes = CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Computers | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.BuiltInGroups | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Groups | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.Users | CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes.WellKnownPrincipals; picker.DefaultObjectTypes = picker.AllowedObjectTypes; picker.AllowedLocations = CubicOrange.Windows.Forms.ActiveDirectory.Locations.All; picker.DefaultLocations = CubicOrange.Windows.Forms.ActiveDirectory.Locations.All; picker.MultiSelect = false; picker.TargetComputer = null; if (picker.ShowDialog(this) != DialogResult.OK) { return; } DirectoryObject[] results = picker.SelectedObjects; if (results == null || results.Length != 1) { return; } if (!String.IsNullOrEmpty(results[0].Path)) { string path = results[0].Path; string[] fields = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string domain = fields[fields.Length - 2]; string account = fields[fields.Length - 1]; if (String.Compare(domain, System.Net.Dns.GetHostName(), StringComparison.InvariantCultureIgnoreCase) == 0) { m_identity = new NTAccount(account); } else { m_identity = new NTAccount(domain, account); } } else { m_identity = new NTAccount(results[0].Name); } if (m_identity != null) { IdentityNameTB.Text = m_identity.ToString(); } } catch (Exception exception) { GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception); } }
private void buttonOpenAdop_OnClick(object sender, RoutedEventArgs e) { using (var pickerDialog = new DirectoryObjectPickerDialog { AllowedObjectTypes = ObjectTypes.Users, DefaultObjectTypes = ObjectTypes.Users, AllowedLocations = Locations.LocalComputer, DefaultLocations = Locations.LocalComputer, MultiSelect = false, ShowAdvancedView = true }) { if (pickerDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TextBoxUsername.Text = ".\\" + pickerDialog.SelectedObject.Name; // ".\\" = Local computer } } }
public static bool SelectAccount(System.Windows.Forms.IWin32Window parent, string targetComputerName, ref string acctName, out bool isGroup, out bool isService, out string sid) { const Locations defLoc = Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.GlobalCatalog | Locations.JoinedDomain | Locations.LocalComputer; var dlg = new DirectoryObjectPickerDialog { TargetComputer = targetComputerName, MultiSelect = false, SkipDomainControllerCheck = true, AllowedLocations = defLoc, DefaultLocations = defLoc, AllowedObjectTypes = ObjectTypes.Users // | ObjectTypes.WellKnownPrincipals | ObjectTypes.Computers; }; if (NativeMethods.AccountUtils.CurrentUserIsAdmin(targetComputerName)) { dlg.AllowedObjectTypes |= ObjectTypes.BuiltInGroups | ObjectTypes.Groups | ObjectTypes.WellKnownPrincipals; } dlg.DefaultObjectTypes = dlg.AllowedObjectTypes; dlg.AttributesToFetch.Add("objectSid"); var res = System.Windows.Forms.DialogResult.None; try { res = dlg.ShowDialog(parent); } catch { } if (res == System.Windows.Forms.DialogResult.OK) { if (dlg.SelectedObject != null) { try { acctName = !string.IsNullOrEmpty(dlg.SelectedObject.Upn) ? NameTranslator.TranslateUpnToDownLevel(dlg.SelectedObject.Upn) : dlg.SelectedObject.Name; } catch { acctName = dlg.SelectedObject.Name; } sid = AttrToString(dlg.SelectedObject.FetchedAttributes[0]); isGroup = dlg.SelectedObject.SchemaClassName.Equals("Group", StringComparison.OrdinalIgnoreCase); isService = NativeMethods.AccountUtils.UserIsServiceAccount(acctName); return(true); } } isGroup = isService = false; sid = null; return(false); }
private void llBrowseUser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog() { AllowedObjectTypes = ObjectTypes.Users, DefaultObjectTypes = ObjectTypes.Users, AllowedLocations = Locations.All, DefaultLocations = Locations.JoinedDomain, MultiSelect = false, ShowAdvancedView = true, AttributesToFetch = { "samAccountName" } }; if (picker.ShowDialog() == DialogResult.OK) { DirectoryObject sel = picker.SelectedObjects.FirstOrDefault(); string userName = sel?.FetchedAttributes.FirstOrDefault() as string; if (sel != null) { txtUser.Text = userName; } } }
private void btnADOP_Click(object sender, EventArgs e) { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog() { AllowedObjectTypes = ObjectTypes.Groups | ObjectTypes.Users, DefaultObjectTypes = ObjectTypes.Groups | ObjectTypes.Users, AllowedLocations = Locations.All, DefaultLocations = Locations.JoinedDomain, MultiSelect = true, ShowAdvancedView = true }; try { if (picker.ShowDialog() == DialogResult.OK) { foreach (var sel in picker.SelectedObjects) { lbGroups.Items.Add(sel.Name); } } } catch (Exception) { } }
private void oAddFromAdButton_Click(object sender, RoutedEventArgs e) { DirectoryObjectPickerDialog oPicker = new DirectoryObjectPickerDialog() { DefaultObjectTypes = ObjectTypes.Users, AllowedObjectTypes = ObjectTypes.Users, MultiSelect = true, DefaultLocations = Locations.GlobalCatalog, AllowedLocations = Locations.All }; oPicker.AttributesToFetch.Add("userCertificate"); oPicker.AttributesToFetch.Add("objectSid"); // show dialog and return if cancelled if (oPicker.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } foreach (DirectoryObject oSelected in oPicker.SelectedObjects) { // skip if no certificate information was found if (oSelected.FetchedAttributes[0] == null) { MessageBox.Show(this, "There was no certificate associated with '" + oSelected.Name + "'.", "No Certificate Information Found", MessageBoxButton.OK, MessageBoxImage.Exclamation); continue; } // if the user has more than one certificate, then we need to wrap the structure as a // single element in an object array; object oAdCertAttribute = oSelected.FetchedAttributes[0]; if (oAdCertAttribute is object[]) { // downselect to only display rsa certs X509Certificate2Collection oCollection = new X509Certificate2Collection(); foreach (byte[] oCertData in (object[])oAdCertAttribute) { oCollection.Add(new X509Certificate2(oCertData)); } // ask the user which certificate to publish oCollection = X509Certificate2UI.SelectFromCollection(oCollection, "Select Certificate", "Select Certificate To Add", X509SelectionFlag.SingleSelection, new WindowInteropHelper(this).Handle); if (oCollection.Count == 0) { continue; } oAdCertAttribute = oCollection[0].RawData; } // add the certificate to the store SecurityIdentifier oSid = new SecurityIdentifier((byte[])oSelected.FetchedAttributes[1], 0); using (X509Certificate2 oCert = new X509Certificate2((byte[])oAdCertAttribute)) { AddCertificate(oCert, oSid.ToString()); } } }
public virtual DialogResult ShowDirectoryObjectPickerDialog(IWin32Window parentWindow) { return(_directoryObjectPicker.ShowDialog(parentWindow)); }
private void btnInvoke_Click(object sender, EventArgs e) { try { var allowedTypes = ObjectTypes.None; foreach (ObjectTypes value in chklistAllowedTypes.CheckedItems) { allowedTypes |= value; } var defaultTypes = ObjectTypes.None; foreach (ObjectTypes value in chklistDefaultTypes.CheckedItems) { defaultTypes |= value; } var allowedLocations = Locations.None; foreach (Locations value in chklistAllowedLocations.CheckedItems) { allowedLocations |= value; } var defaultLocations = Locations.None; foreach (Locations value in chklistDefaultLocations.CheckedItems) { defaultLocations |= value; } // Show dialog var picker = new DirectoryObjectPickerDialog { AllowedObjectTypes = allowedTypes, DefaultObjectTypes = defaultTypes, AllowedLocations = allowedLocations, DefaultLocations = defaultLocations, MultiSelect = chkMultiSelect.Checked, TargetComputer = txtTargetComputer.Text, SkipDomainControllerCheck = chkSkipDcCheck.Checked, ShowAdvancedView = chkShowAdvanced.Checked }; if (comboPathProvider.SelectedItem is ADsPathsProviders) { picker.Providers = (ADsPathsProviders)comboPathProvider.SelectedItem; } if (txUserName.TextLength > 0) { picker.SetCredentials(txUserName.Text, txPassword.Text); } foreach (string attribute in chklistAttributes.CheckedItems) { var trimmed = attribute.Trim(); if (trimmed.Length > 0) { picker.AttributesToFetch.Add(trimmed); } } var dialogResult = picker.ShowDialog(this); if (dialogResult == DialogResult.OK) { var results = picker.SelectedObjects; if (results == null) { txtFeedback.Text = "Results null."; return; } var sb = new StringBuilder(); for (var i = 0; i <= results.Length - 1; i++) { sb.Append(string.Format("Name: \t\t {0}", results[i].Name)); sb.Append(Environment.NewLine); sb.Append(string.Format("UPN: \t\t {0}", results[i].Upn)); sb.Append(Environment.NewLine); sb.Append(string.Format("Path: \t\t {0}", results[i].Path)); sb.Append(Environment.NewLine); sb.Append(string.Format("Schema Class: \t\t {0} ", results[i].SchemaClassName)); sb.Append(Environment.NewLine); var downLevelName = ""; try { if (!string.IsNullOrEmpty(results[i].Upn)) { downLevelName = NameTranslator.TranslateUpnToDownLevel(results[i].Upn); } } catch (Exception ex) { downLevelName = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); } sb.Append(string.Format("Down-level Name: \t\t {0} ", downLevelName)); sb.Append(Environment.NewLine); sb.AppendFormat("Fetched {0} attributes", results[i].FetchedAttributes.Length); sb.Append(Environment.NewLine); for (var j = 0; j < results[i].FetchedAttributes.Length; j++) { var attributeName = picker.AttributesToFetch[j]; sb.AppendFormat("\t{0}. {1}", j, attributeName); sb.Append(Environment.NewLine); var multivaluedAttribute = results[i].FetchedAttributes[j]; if (!(multivaluedAttribute is IEnumerable) || multivaluedAttribute is byte[] || multivaluedAttribute is string) { multivaluedAttribute = new[] { multivaluedAttribute } } ; foreach (var attribute in (IEnumerable)multivaluedAttribute) { sb.Append("\t"); if (attribute == null) { sb.Append("(not present)"); } else if (attribute is byte[]) { var bytes = (byte[])attribute; if (attributeName.Equals("objectSid", StringComparison.OrdinalIgnoreCase)) { sb.Append(SIDBytesToString(bytes)); } else { sb.Append(GuidBytesToString(bytes)); } } else { sb.AppendFormat("{0}", attribute); } sb.Append(Environment.NewLine); } sb.Append(Environment.NewLine); } sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); } txtFeedback.Text = sb.ToString(); } else { txtFeedback.Text = "Dialog result: " + dialogResult; } } catch (Exception e1) { MessageBox.Show(e1.ToString()); } }
private async void OnSetWindowsAuthenticationExecute(User user) { DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog() { AllowedObjectTypes = ObjectTypes.All, DefaultObjectTypes = ObjectTypes.All, AllowedLocations = Locations.All, DefaultLocations = Locations.JoinedDomain, MultiSelect = true, ShowAdvancedView = true, AttributesToFetch = new List <string>() { "objectSid" } }; if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DirectoryObject[] results = picker.SelectedObjects; if (results == null) { return; } var sid = ""; for (int i = 0; i <= results.Length - 1; i++) { string downLevelName = ""; try { if (!string.IsNullOrEmpty(results[i].Upn)) { downLevelName = NameTranslator.TranslateUpnToDownLevel(results[i].Upn); } } catch (Exception ex) { downLevelName = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); } for (int j = 0; j < results[i].FetchedAttributes.Length; j++) { object multivaluedAttribute = results[i].FetchedAttributes[j]; if (!(multivaluedAttribute is IEnumerable) || multivaluedAttribute is byte[] || multivaluedAttribute is string) { multivaluedAttribute = new[] { multivaluedAttribute } } ; foreach (object attribute in (IEnumerable)multivaluedAttribute) { if (attribute is byte[]) { byte[] bytes = (byte[])attribute; sid = BytesToString(bytes); } } } } user.Sid = sid; await _repository.UpdateUserAsync(user); await LoadAsync(0); } }
private void btnInvoke_Click(object sender, EventArgs e) { try { ObjectTypes allowedTypes = ObjectTypes.None; foreach (ObjectTypes value in chklistAllowedTypes.CheckedItems) { allowedTypes |= value; } ObjectTypes defaultTypes = ObjectTypes.None; foreach (ObjectTypes value in chklistDefaultTypes.CheckedItems) { defaultTypes |= value; } Locations allowedLocations = Locations.None; foreach (Locations value in chklistAllowedLocations.CheckedItems) { allowedLocations |= value; } Locations defaultLocations = Locations.None; foreach (Locations value in chklistDefaultLocations.CheckedItems) { defaultLocations |= value; } // Show dialog DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog(); picker.AllowedObjectTypes = allowedTypes; picker.DefaultObjectTypes = defaultTypes; picker.AllowedLocations = allowedLocations; picker.DefaultLocations = defaultLocations; picker.MultiSelect = chkMultiSelect.Checked; picker.TargetComputer = txtTargetComputer.Text; picker.SkipDomainControllerCheck = chkSkipDcCheck.Checked; picker.ShowAdvancedView = chkShowAdvanced.Checked; if (comboPathProvider.SelectedItem is ADsPathsProviders) { picker.Providers = (ADsPathsProviders)comboPathProvider.SelectedItem; } foreach (string attribute in chklistAttributes.CheckedItems) { string trimmed = attribute.Trim(); if (trimmed.Length > 0) { picker.AttributesToFetch.Add(trimmed); } } DialogResult dialogResult = picker.ShowDialog(this); if (dialogResult == DialogResult.OK) { DirectoryObject[] results = picker.SelectedObjects; if (results == null) { txtFeedback.Text = "Results null."; return; } StringBuilder sb = new StringBuilder(); for (int i = 0; i <= results.Length - 1; i++) { sb.Append(string.Format("Name: \t\t {0}", results[i].Name)); sb.Append(Environment.NewLine); sb.Append(string.Format("UPN: \t\t {0}", results[i].Upn)); sb.Append(Environment.NewLine); sb.Append(string.Format("Path: \t\t {0}", results[i].Path)); sb.Append(Environment.NewLine); sb.Append(string.Format("Schema Class: \t\t {0} ", results[i].SchemaClassName)); sb.Append(Environment.NewLine); string downLevelName = ""; try { if (!string.IsNullOrEmpty(results[i].Upn)) { downLevelName = NameTranslator.TranslateUpnToDownLevel(results[i].Upn); } } catch (Exception ex) { downLevelName = string.Format("{0}: {1}", ex.GetType().Name, ex.Message); } sb.Append(string.Format("Down-level Name: \t\t {0} ", downLevelName)); sb.Append(Environment.NewLine); sb.AppendFormat("Fetched {0} attributes", results[i].FetchedAttributes.Length); sb.Append(Environment.NewLine); for (int j = 0; j < results[i].FetchedAttributes.Length; j++) { sb.AppendFormat("\t{0}. {1}", j, picker.AttributesToFetch[j]); sb.Append(Environment.NewLine); object multivaluedAttribute = results[i].FetchedAttributes[j]; if (!(multivaluedAttribute is IEnumerable) || multivaluedAttribute is byte[] || multivaluedAttribute is string) { multivaluedAttribute = new[] { multivaluedAttribute } } ; foreach (object attribute in (IEnumerable)multivaluedAttribute) { sb.Append("\t"); if (attribute == null) { sb.Append("(not present)"); } else if (attribute is byte[]) { byte[] bytes = (byte[])attribute; sb.Append(BytesToString(bytes)); } else { sb.AppendFormat("{0}", attribute); } sb.Append(Environment.NewLine); } sb.Append(Environment.NewLine); } sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); } txtFeedback.Text = sb.ToString(); } else { txtFeedback.Text = "Dialog result: " + dialogResult; } } catch (Exception e1) { MessageBox.Show(e1.ToString()); } }
/// <summary> /// ADs the object picker show dialog. /// </summary> /// <param name="handle">The owner handle.</param> /// <param name="showLocalUsersAndGroups">if set to <c>true</c> [show local users and groups].</param> /// <param name="showOnlyUsers">if set to <c>true</c> [show only users].</param> /// <param name="multipleSelection">if set to <c>true</c> [multiple selection].</param> /// <returns></returns> public static ADObject[] ADObjectPickerShowDialog(IWin32Window owner, bool showLocalUsersAndGroups, bool showOnlyUsers, bool multipleSelection) { #region OLD CODE //try //{ // // Initialize 1st search scope // uint flType = 0; // flType = flType | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_GLOBAL_CATALOG | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE | // DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE; // //DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_WORKGROUP; // if (showLocalUsersAndGroups) // flType = flType | DSOP_SCOPE_TYPE_FLAGS.DSOP_SCOPE_TYPE_TARGET_COMPUTER; // uint flScope = // DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_PROVIDER_LDAP | // DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_USERS | // DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_PROVIDER_WINNT | // DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_STARTING_SCOPE | // DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_WANT_DOWNLEVEL_BUILTIN_PATH; // Starting !?; // if (!showOnlyUsers) // flScope = flScope | DSOP_SCOPE_INIT_INFO_FLAGS.DSOP_SCOPE_FLAG_DEFAULT_FILTER_GROUPS; // uint flBothModes = // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_INCLUDE_ADVANCED_VIEW | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_USERS; // if (!showOnlyUsers) // flBothModes = flBothModes | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_BUILTIN_GROUPS | // //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_DL | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_DOMAIN_LOCAL_GROUPS_SE | // //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_GLOBAL_GROUPS_DL | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_GLOBAL_GROUPS_SE | // //DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_UNIVERSAL_GROUPS_DL | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_UNIVERSAL_GROUPS_SE | // DSOP_FILTER_FLAGS_FLAGS.DSOP_FILTER_WELL_KNOWN_PRINCIPALS; // uint flDownlevel = // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_ANONYMOUS | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_AUTHENTICATED_USER | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_BATCH | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_CREATOR_GROUP | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_CREATOR_OWNER | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_DIALUP | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_INTERACTIVE | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_LOCAL_SERVICE | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_NETWORK | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_NETWORK_SERVICE | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_REMOTE_LOGON | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_SERVICE | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_SYSTEM | // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_TERMINAL_SERVER | // DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_USERS; // //DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_WORLD; // if (!showOnlyUsers) // { // flDownlevel = flDownlevel // | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_ALL_WELLKNOWN_SIDS // | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_GLOBAL_GROUPS // | DSOP_DOWNLEVEL_FLAGS.DSOP_DOWNLEVEL_FILTER_LOCAL_GROUPS; // } // ADObjectPickerClass cadObjectPicker = new ADObjectPickerClass(); // cadObjectPicker.InitInfo_OptionFlags = DSOP_INIT_INFO_FLAGS.DSOP_FLAG_SKIP_TARGET_COMPUTER_DC_CHECK; // if (multipleSelection) // { // cadObjectPicker.InitInfo_OptionFlags = cadObjectPicker.InitInfo_OptionFlags // | DSOP_INIT_INFO_FLAGS.DSOP_FLAG_MULTISELECT; // } // cadObjectPicker.ScopeTypeFlags = flType; // cadObjectPicker.ScopeFlags = flScope; // cadObjectPicker.UplevelFilterFlags_Both = flBothModes; // cadObjectPicker.DownLevelFilterFlags = flDownlevel; // cadObjectPicker.InvokeDialog(handle.ToInt32()); // ADObjectColl result = (ADObjectColl)cadObjectPicker.ADObjectsColl; // ADObject[] results = new ADObject[result.Count]; // for (uint j = 1; j <= result.Count; j++) // { // try // { // int i = (int)j; // ADObjectInfo info = (ADObjectInfo)result.Item(i); // results[j - 1] = new ADObject(); // results[j - 1].ADSPath = info.ADPath; // results[j - 1].ClassName = info.Class; // results[j - 1].Name = info.Name; // results[j - 1].UPN = info.UPN; // } // catch // { // continue; // } // } // return results; //} //catch (System.ArgumentException) //{ // return new ADObject[0]; //} #endregion OLD CODE try { // Show dialog DirectoryObjectPickerDialog picker = new DirectoryObjectPickerDialog(); ObjectTypes allowedTypes = ObjectTypes.None; if (!showOnlyUsers) { allowedTypes = ObjectTypes.BuiltInGroups | ObjectTypes.Groups | ObjectTypes.Users | ObjectTypes.WellKnownPrincipals; } else { allowedTypes = ObjectTypes.Users; } ObjectTypes defaultTypes = allowedTypes; picker.AllowedObjectTypes = allowedTypes; picker.DefaultObjectTypes = defaultTypes; Locations allowedLocations = Locations.None; Locations defaultLocations = Locations.None; if (showLocalUsersAndGroups) { allowedLocations = Locations.All; defaultLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain; if (Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.CurrentCultureIgnoreCase)) { //NOT JOINED TO A DOMAIN defaultLocations |= Locations.LocalComputer; } } else { allowedLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain; defaultLocations = Locations.GlobalCatalog | Locations.EnterpriseDomain | Locations.ExternalDomain | Locations.JoinedDomain; } picker.AllowedLocations = allowedLocations; picker.DefaultLocations = defaultLocations; picker.MultiSelect = multipleSelection; picker.ShowAdvancedView = true; DialogResult dialogResult = picker.ShowDialog(owner); if (dialogResult == DialogResult.OK) { if (picker.SelectedObjects == null) { return(new ADObject[0]); } ADObject[] results = new ADObject[picker.SelectedObjects.Length]; for (int j = 0; j < picker.SelectedObjects.Length; j++) { try { DirectoryObject info = (DirectoryObject)picker.SelectedObjects[j]; results[j] = new ADObject(); results[j].ADSPath = info.Path; results[j].ClassName = info.SchemaClassName; results[j].Name = info.Name; results[j].UPN = info.Upn; } catch { continue; } } return(results); } else { return(new ADObject[0]); } } catch { return(new ADObject[0]); } }