OrenRozen
asked on
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
Thanks.
SelectUsersOrGroups.jpg
ASKER
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.
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++;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
did you read the section Using the code in the code project site?
ASKER
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.
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.
http://www.codeproject.com/KB/winsdk/bfobjectselection2.aspx