惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
B
Blog
N
Netflix TechBlog - Medium
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
O
OpenAI News
M
MIT News - Artificial intelligence
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
Vercel News
Vercel News
T
Tenable Blog
Security Latest
Security Latest
C
Check Point Blog
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
雷峰网
雷峰网
IT之家
IT之家
H
Hacker News: Front Page
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Last Week in AI
Last Week in AI
G
Google Developers Blog
Forbes - Security
Forbes - Security
The Register - Security
The Register - Security
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Martin Fowler
Martin Fowler
K
Kaspersky official blog
P
Proofpoint News Feed
T
Threatpost
Google Online Security Blog
Google Online Security Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - eFeng.Leung

枚举Exchange Server、SotreGroups和MailStore Single Sign-On for everyone 关于AD编程的一些资料 zz 不同的asp.net web应用程序间共享Session/Application - eFeng.Leung - 博客园 Code Project中几篇关于DNN的文章 Authenticate a user against the Active Directory using the user ID and password User Object User Interface Mapping Lists all entries in the Active Directory Active Directory and .NET LDAP, IIS and WinNT Directory Services 无法破解的软件注册码算法 SQL2K集群 绑定在 TCP 端口 1433 上失败 使用HTTP访问2003表单登录页 (转) FYI: Getting Started with WebDAV 遭遇 对路径“C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\aa\……”的访问被拒绝 - eFeng.Leung 网络负载平衡部署 Group Panel 在DataGrid里显示Excel文件数据 鼠标移动,改变datagrid里行的色
Using Active Directory
eFeng.Leung · 2006-04-04 · via 博客园 - eFeng.Leung

Using Active Directory
By  Vivek Sharma July 31, 2002

This sample code can sense current context in Active Directory, checks for the existence of attributes, provides a list of all the attributes in Active Directory and can add a user to Active Directory.

public void AddUser()
{
string strDomain="";
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher 
= new System.DirectoryServices.DirectorySearcher();
RootDSE
=DSESearcher.SearchRoot.Path;
MessageBox.Show(RootDSE);
RootDSE
=RootDSE.Insert(7,"CN=Users,");
MessageBox.Show(RootDSE);
MessageBox.Show(strDomain);
DirectoryEntry myDE 
= new DirectoryEntry(RootDSE);
DirectoryEntries myEntries 
= myDE.Children;
// Create a new entry 'Sample' in the container.
DirectoryEntry myDirectoryEntry = myEntries.Add("CN="+txtUserName.Text, "user");
MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
myDirectoryEntry.Properties[
"userPrincipalName"].Value=txtPrincipal.Text;
myDirectoryEntry.Properties[
"name"].Value=txtUserName.Text;
myDirectoryEntry.Properties[
"samAccountName"].Value=txtUserName.Text;
myDirectoryEntry.CommitChanges();
}

private void button2_Click(object sender, System.EventArgs e)
{
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher 
= new System.DirectoryServices.DirectorySearcher();
RootDSE
=DSESearcher.SearchRoot.Path;
MessageBox.Show(
"Searching for user Class in "+RootDSE);
DirectoryEntry entry 
= new DirectoryEntry(RootDSE);
System.DirectoryServices.DirectorySearcher mySearcher 
= new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter 
= ("(ObjectClass=user)");
System.DirectoryServices.SearchResult resEnt
=mySearcher.FindOne();
entry
=resEnt.GetDirectoryEntry();
MessageBox.Show(
"Entry Of attribute found = " + entry.Properties.Contains(txtAtt.Text).ToString());
}

private void button3_Click(object sender, System.EventArgs e)
{
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher 
= new System.DirectoryServices.DirectorySearcher();
RootDSE
=DSESearcher.SearchRoot.Path;
MessageBox.Show(
"Searching for user Class in "+RootDSE);
DirectoryEntry entry 
= new DirectoryEntry(RootDSE);
System.DirectoryServices.DirectorySearcher mySearcher 
= new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter 
= ("(ObjectClass=user)");
System.DirectoryServices.SearchResult resEnt
=mySearcher.FindOne();
entry
=resEnt.GetDirectoryEntry();
System.Collections.IEnumerator en 
= entry.Properties.PropertyNames.GetEnumerator();
while(en.MoveNext())
{
listBox1.Items.Add(en.Current.ToString());
}

}

public void AddUser1()
{
string strDomain="";
string RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher 
= new System.DirectoryServices.DirectorySearcher();
RootDSE
=DSESearcher.SearchRoot.Path;
MessageBox.Show(RootDSE);
MessageBox.Show(RootDSE);
MessageBox.Show(strDomain);
DirectoryEntry myDE 
= new DirectoryEntry(RootDSE);
DirectoryEntries myEntries 
= myDE.Children;
// Create a new entry 'Sample' in the container.
DirectoryEntry myDirectoryEntry = myEntries.Add("CN="+txtUserName.Text, "CB");
MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
MessageBox.Show(myDirectoryEntry.Path.ToString());
System.Collections.IEnumerator en 
= myDirectoryEntry.Properties.PropertyNames.GetEnumerator();
while(en.MoveNext())
{
MessageBox.Show(en.Current.ToString());
}

myDirectoryEntry.CommitChanges();
}