亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Active Directory如何用C#進(jìn)行增加、刪除、修

系統(tǒng) 1623 0

首先我們來了解一下什么是Active Directory。不用我描述,看以下網(wǎng)址,或在.net自帶幫助文檔里根據(jù)Active Directory關(guān)鍵字一搜,就什么都明白了。
http://developer.ccidnet.com/pub/article/c322_a28703_p2.html

接下來,我們來看看權(quán)限。你可以通過“網(wǎng)上鄰居--整個(gè)網(wǎng)絡(luò)--Directory--demain(你的域名)”你就可以看到所有關(guān)于域下的信息,粗一看就知道是怎么回事了。
需要告訴大家的:所有組織單位下的用戶都在Users(容器)--Demain Users(組)中
用代碼進(jìn)行訪問時(shí),如果你是域管理員用戶,則可以做任何操作,否則,只能查詢用戶屬性。

private void SearchUser()
{
string domainName = "Domain";
string groupName = "Domain Users";
string dirmemName="";
//在Domain Users域用戶里取得每個(gè)用戶名
System.DirectoryServices.DirectoryEntry group = new System.DirectoryServices.DirectoryEntry("WinNT://" domainName "/" groupName ",group");
foreach(Object member in (IEnumerable)group.Invoke("Members"))
{
//根據(jù)很個(gè)用戶生成如:"LDAP://OU=套裝軟體課,OU=系統(tǒng)開發(fā)部,OU=資訊服務(wù)處,OU=營運(yùn)支援中心,OU=XX公司,DC=Domain,DC=com,DC=cn"
System.DirectoryServices.DirectoryEntry dirmem = new System.DirectoryServices.DirectoryEntry(member);
dirmemName=dirmem.Name;
string DomainName="Domain";
string FilterStr = "(sAMAccountname=" dirmemName ")";
System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter = FilterStr;
System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
System.DirectoryServices.DirectoryEntry MyUser = FindRes.GetDirectoryEntry();
string OUPath=MyUser.Parent.Path;
//找到該用戶所在的LDAP:后,由域管理員登錄,并取得該用戶的所在屬性。
string strFieldsValue="",strFields="";
System.DirectoryServices.DirectoryEntry myds=new System.DirectoryServices.DirectoryEntry(OUPath,"域管理員名","域管理員密碼");
foreach(System.DirectoryServices.DirectoryEntry tempEntry in myds.Children)
{
if(tempEntry.SchemaClassName.ToString() == "user" && tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()==dirmemName)
{
foreach (string propertyName in tempEntry.Properties.PropertyNames )
{
string oneNode = propertyName ": "
entry.Properties[propertyName][0].ToString();
this.Textbox1.Text=oneNode;
}
}

?

?
--------------------------------------------------------------------------------

public void AddUser(string strPath,string Username,string ChineseName)//strPath 增加用戶至哪個(gè)組織單位如"LDAP://OU=XX公司,DC=Domain,DC=com"帳號(hào)、中文名{
try
{
string RootDSE;
//System.DirectoryServices.DirectorySearcher DSESearcher= new System.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE="LDAP://DC=Domain,DC=com";
//RootDSE=RootDSE.Insert(7,"CN=Users,");
System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.DirectoryEntries myEntries = myDE.Children;
// Create a new entry 'Sample' in the container.

?

string strname="CN=" ChineseName;
System.DirectoryServices.DirectoryEntry myDirectoryEntry = myEntries.Add(strname, "user");

//MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
myDirectoryEntry.Properties["userPrincipalName"].Value=Username;
myDirectoryEntry.Properties["name"].Value=ChineseName;
myDirectoryEntry.Properties["samAccountName"].Value=Username;
myDirectoryEntry.Properties["userAccountControl"].Value =66048; //590336;
myDirectoryEntry.CommitChanges();
}


-------------------------------------------------------------------------------- http://www.mscto.com/

private void addOU(string strPath,string OUName)//增加組織到strPath組織單位下,組織名稱
{
try
{
//String RootDSE;
//System.DirectoryServices.DirectorySearcher DSESearcher= new System.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE=" http://www.cnblogs.com/ahjxxy/admin/ldap://OU/ =百意時(shí)尚廣場,DC=Domain,DC=com";

System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.DirectoryEntries myEntries = myDE.Children;
string name="OU=" OUName;
System.DirectoryServices.DirectoryEntry myDirectoryEntry = myEntries.Add(name,"organizationalUnit");

myDirectoryEntry.Properties["name"].Value=OUName;
myDirectoryEntry.Properties["instanceType"].Value=4;
myDirectoryEntry.Properties["distinguishedName"].Value="OU=" OUName ",DC=Domain,DC=COM)";
myDirectoryEntry.Properties["objectCategory"].Value="CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=sedep,DC=COM";
myDirectoryEntry.Properties["ou"].Value=OUName;
myDirectoryEntry.Properties["postalCode"].Value="777";

myDirectoryEntry.CommitChanges();
//UserMoveto(" http://www.cnblogs.com/ahjxxy/admin/ldap://OU/ =" OUName ",DC=sedep,DC=com",strPath);
}
catch(Exception RaiseErr)
{
MessageBox.Show (RaiseErr.Message);
}
}


-------------------------------------------------------------------------------- 軟件開發(fā)網(wǎng)

private void ModifyUser()
{
try
{
string DomainName="Domain";
string FilterStr = "(sAMAccountname=karlluo)";
System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter = FilterStr;
System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
string tt=FindRes.Path;
System.DirectoryServices.DirectoryEntry MyUser = FindRes.GetDirectoryEntry();
string OUPath=MyUser.Parent.Path;

DirectoryEntry myds=new DirectoryEntry(OUPath,"域管理員名","域管理員密碼");

foreach(System.DirectoryServices.DirectoryEntry tempEntry in myds.Children)
{
if(tempEntry.SchemaClassName.ToString() == "user")
{
if(tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()=="karlluo")
{
tempEntry.UsePropertyCache=true;
tempEntry.Properties["st"].Value="yyyyyyyyyyyyyyyy";
//newEntry.Properties["userPrincipalName"].Value="userID";
tempEntry.CommitChanges();
}
}
}


}
catch(Exception RaiseErr)
{
MessageBox.Show (RaiseErr.Message);
} 軟件開發(fā)網(wǎng)

}

?

Active Directory如何用C#進(jìn)行增加、刪除、修改、查詢用戶與組織單位


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 97se亚洲国产综合自在线观看 | 被公侵犯肉体中文字幕一区二区 | 日本1区2区 | 青青青国产免费线在 | 四虎永久在线精品免费观看地址 | 激情综合在线观看 | 在线亚洲 欧美 日本专区 | 国产毛片在线 | 亚洲最大在线视频 | 黄视频在线观看www 黄视频在线观看网站 | 手机福利片 | 97免费观看视频 | 亚洲日韩欧洲无码av夜夜摸 | 日本精品不卡 | 一区二区三区美女视频 | 国产在线19禁免费观看国产 | 日韩精品一区二区三区 在线观看 | 奇米777影视成人四色 | 欧美另类网站 | 激情伊人网 | 91在线激情在线观看 | 99精品视频在线播放2 | 久久精品中文字幕有码日本 | 91最新视频在线观看 | 色久天| 99re这里只有精品66 | 精品视频在线免费 | 91手机看片国产永久免费 | 亚洲精品久久99久久一区 | 久久久久草 | 亚洲 欧美精品 | 久久精品国产久精国产 | 国产精品一区视频 | 亚洲精品国产经典一区二区 | 亚洲一区二区三区高清视频 | 成人午夜爽爽爽免费视频 | 久久国产精品只做精品 | 欧美性色欧美a在线观看 | 中文字幕 国产 | 精品久久久久久中文字幕网 | 特黄级 |