I’m needing to modify a custom attribute we’ve added to the schema, but on an all user basis. The attribute is an MD5 hash, that I’m already storing as a public variable. I’m trying to get a list of all users within specified OU to be listed within the listbox so that you can select all the users or individual users to have the values applied to.
Here is my current code for Form1.cs
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;
using System.Security.Cryptography;
using System.DirectoryServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
String Password;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
Password = textBox1.Text;
}
private void button1_Click(object sender, EventArgs e)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(Password);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
Password = s.ToString();
textBox2.Text = Password;
}
private void button2_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
If you’re on .NET 3.5 or newer, you can use a
PrincipalSearcherand a “query-by-example” principal to do your searching:If you haven’t already – absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in
System.DirectoryServices.AccountManagementYou can specify any of the properties on the
UserPrincipaland use those as “query-by-example” for yourPrincipalSearcher.