• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2456
  • Last Modified:

how to open 'Select Users Or Groups' window using c#

I need a c# (VS2008) code to open the 'Select Users Or Groups' window, select users and/or groups of the connected computer or AD and copy them to any kind of list (string[]' listview, etc).

Thanks.
SelectUsersOrGroups.jpg
0
OrenRozen
Asked:
OrenRozen
  • 3
  • 2
1 Solution
 
OrenRozenAuthor Commented:
I've already found both links and downloaded the sources from codeproject, but I'm unable to figure out how to use it.

I've copy the code from the codeproject page, added a reference to the helper dll but having problem with
'ADFlagConstants'.

Can you please help in completing the code to open the dialog box?

Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace MySelectUsersAndGroups
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            // grab the helper object
 
            ObjectPickerHelper.CADObjectPicker picker =
               new ObjectPickerHelper.CADObjectPickerClass();
            // mess with the flags
 
            picker.ScopeFlags =
             (uint)(ADFlagConstants.DSOP_SCOPE_FLAG.WANT_PROVIDER_WINNT);
            picker.ScopeTypeFlags =
             (uint)(ADFlagConstants.DSOP_SCOPE_TYPE.DOWNLEVEL_JOINED_DOMAIN |
                  ADFlagConstants.DSOP_SCOPE_TYPE.ENTERPRISE_DOMAIN |
                  ADFlagConstants.DSOP_SCOPE_TYPE.EXTERNAL_DOWNLEVEL_DOMAIN |
                  ADFlagConstants.DSOP_SCOPE_TYPE.EXTERNAL_UPLEVEL_DOMAIN |
                  ADFlagConstants.DSOP_SCOPE_TYPE.UPLEVEL_JOINED_DOMAIN |
                  ADFlagConstants.DSOP_SCOPE_TYPE.USER_ENTERED_DOWNLEVEL_SCOPE |
                  ADFlagConstants.DSOP_SCOPE_TYPE.USER_ENTERED_UPLEVEL_SCOPE |
                  ADFlagConstants.DSOP_SCOPE_TYPE.GLOBAL_CATALOG);
            picker.UplevelFilterFlags_Both =
             (uint)ADFlagConstants.DSOP_FILTER.COMPUTERS;
            picker.UplevelFilterFlags_Mixed = 0;
            picker.UplevelFilterFlags_Native = 0;
            picker.DownLevelFilterFlags =
             ADFlagConstants.DSOP_DOWNLEVEL_FILTER_COMPUTERS;
            picker.InitInfo_OptionFlags = (uint)ADFlagConstants.DSOP_FLAG.MULTISELECT;
 
 
            // show the dialog
 
            picker.InvokeDialog(UsersOrGroupsFrm.ActiveForm.Handle.ToInt32());
 
            // somehow C# seems more picky with the types than VB, 
 
            // so you have to use an intermediate var.
 
            ObjectPickerHelper.CADObjectColl coll =
             (ObjectPickerHelper.CADObjectColl)picker.ADObjectsColl;
 
            // and walk the collection
 
            int i = 0;
 
            foreach (ObjectPickerHelper.CADObjectInfo InfoObject in coll)
            {
                ListViewItem theItem = new ListViewItem(InfoObject.Name, i);
                theItem.SubItems.Add(InfoObject.Class);
                theItem.SubItems.Add(InfoObject.ADPath);
                theItem.SubItems.Add(InfoObject.UPN);
                listViewResults.Items.Add(theItem);
                i++;
            }
 
        }
    }
}

Open in new window

0
 
OrenRozenAuthor Commented:
solution was not provided
0
 
Anurag ThakurTechnical ManagerCommented:
did you read the section Using the code in the code project site?
0
 
OrenRozenAuthor Commented:
yes I did.

As I said, I've copy the code from the codeproject page, added a reference to the helper dll but having problem with
'ADFlagConstants'.

You can see it in the attached code in my previous replay.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now