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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 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 - eFeng.Leung 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();
}