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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Last Watchdog
The Last Watchdog
T
Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security @ Cisco Blogs
S
Securelist
L
LINUX DO - 最新话题
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园_首页
博客园 - Franky
H
Heimdal Security Blog
G
Google Developers Blog
N
News and Events Feed by Topic
Cisco Talos Blog
Cisco Talos Blog
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
S
Schneier on Security
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
Simon Willison's Weblog
Simon Willison's Weblog
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
Latest news
Latest news
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
N
Netflix TechBlog - Medium
T
Tor Project blog
月光博客
月光博客
D
Docker
美团技术团队
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyberwarzone
Cyberwarzone
小众软件
小众软件
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
L
LINUX DO - 热门话题
O
OpenAI News
人人都是产品经理
人人都是产品经理
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
V2EX
C
Cisco Blogs
NISL@THU
NISL@THU
Recent Commits to openclaw:main
Recent Commits to openclaw:main
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美

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