|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
另外,小型软件代码重用价值低,没有必要跨平台;大型软件,有严格的规划、部署,不可以随意跨平台。active起首我们来懂得一下甚么是ActiveDirectory。不必我形貌,看以下网址,或在.net自带匡助文档里依据ActiveDirectory关头字一搜,就甚么都分明了。
接上去,我们来看看权限。你能够经由过程“网上邻人--全部收集--Directory--demain(你的域名)”你就能够看到一切关于域下的信息,粗一看就晓得是怎样回事了。
必要告知人人的:一切构造单元下的用户都在Users(容器)--DemainUsers(组)中
用代码举行会见时,假如你是域办理员用户,则能够做任何操纵,不然,只能查询用户属性。
privatevoidSearchUser()
{
stringdomainName="Domain";
stringgroupName="DomainUsers";
stringdirmemName="";
//在DomainUsers域用户里获得每一个用户名
System.DirectoryServices.DirectoryEntrygroup=newSystem.DirectoryServices.DirectoryEntry("WinNT://"+domainName+"/"+groupName+",group");
foreach(Objectmemberin(IEnumerable)group.Invoke("Members"))
{
//依据很个用户天生如:"LDAP://OU=套装软体课,OU=体系开辟部,OU=资讯服务处,OU=营运增援中央,OU=XX公司,DC=Domain,DC=com,DC=cn"
System.DirectoryServices.DirectoryEntrydirmem=newSystem.DirectoryServices.DirectoryEntry(member);
dirmemName=dirmem.Name;
stringDomainName="Domain";
stringFilterStr="(sAMAccountname="+dirmemName+")";
System.DirectoryServices.DirectorySearcherFindMe=newSystem.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter=FilterStr;
System.DirectoryServices.SearchResultFindRes=FindMe.FindOne();
System.DirectoryServices.DirectoryEntryMyUser=FindRes.GetDirectoryEntry();
stringOUPath=MyUser.Parent.Path;
//找到该用户地点的LDAP:后,由域办理员登录,并获得该用户的地点属性。
stringstrFieldsValue="",strFields="";
System.DirectoryServices.DirectoryEntrymyds=newSystem.DirectoryServices.DirectoryEntry(OUPath,"域办理员名","域办理员暗码");
foreach(System.DirectoryServices.DirectoryEntrytempEntryinmyds.Children)
{
if(tempEntry.SchemaClassName.ToString()=="user"&&tempEntry.Properties["sAMAccountName"].Value.ToString().ToLower()==dirmemName)
{
foreach(stringpropertyNameintempEntry.Properties.PropertyNames)
{
stringoneNode=propertyName+":"+
entry.Properties[propertyName][0].ToString();
this.Textbox1.Text=oneNode;
}
}
-------------------------------------------
publicvoidAddUser(stringstrPath,stringUsername,stringChineseName)//strPath增添用户至哪一个构造单元如"LDAP://OU=XX公司,DC=Domain,DC=com"帐号、中文名{
try
{
stringRootDSE;
//System.DirectoryServices.DirectorySearcherDSESearcher=newSystem.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE="LDAP://DC=Domain,DC=com";
//RootDSE=RootDSE.Insert(7,"CN=Users,");
System.DirectoryServices.DirectoryEntrymyDE=newSystem.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.DirectoryEntriesmyEntries=myDE.Children;
//CreateanewentrySampleinthecontainer.
stringstrname="CN="+ChineseName;
System.DirectoryServices.DirectoryEntrymyDirectoryEntry=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();
}
----------------------------------------------
privatevoidaddOU(stringstrPath,stringOUName)//增添构造到strPath构造单元下,构造称号
{
try
{
//StringRootDSE;
//System.DirectoryServices.DirectorySearcherDSESearcher=newSystem.DirectoryServices.DirectorySearcher();
//RootDSE=DSESearcher.SearchRoot.Path;
//RootDSE="LDAP://OU=百意时髦广场,DC=Domain,DC=com";
System.DirectoryServices.DirectoryEntrymyDE=newSystem.DirectoryServices.DirectoryEntry(strPath);
System.DirectoryServices.DirectoryEntriesmyEntries=myDE.Children;
stringname="OU="+OUName;
System.DirectoryServices.DirectoryEntrymyDirectoryEntry=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("LDAP://OU="+OUName+",DC=sedep,DC=com",strPath);
}
catch(ExceptionRaiseErr)
{
MessageBox.Show(RaiseErr.Message);
}
}
---------------------------------------------
privatevoidModifyUser()
{
try
{
stringDomainName="Domain";
stringFilterStr="(sAMAccountname=karlluo)";
System.DirectoryServices.DirectorySearcherFindMe=newSystem.DirectoryServices.DirectorySearcher(DomainName);
FindMe.Filter=FilterStr;
System.DirectoryServices.SearchResultFindRes=FindMe.FindOne();
stringtt=FindRes.Path;
System.DirectoryServices.DirectoryEntryMyUser=FindRes.GetDirectoryEntry();
stringOUPath=MyUser.Parent.Path;
DirectoryEntrymyds=newDirectoryEntry(OUPath,"域办理员名","域办理员暗码");
foreach(System.DirectoryServices.DirectoryEntrytempEntryinmyds.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(ExceptionRaiseErr)
{
MessageBox.Show(RaiseErr.Message);
}
}
兄弟们,想来你们都看过了昨天的比赛了。我现在的痛苦状跟当时应该差不多。希望本版.net老师不吝赐教,为小弟这一批迷途的羊羔指一条阳光之道!您也知道:学习技术如果只有一个人摸索,那是一件多么痛苦的事情!还有,如果万辛能得名师或长者指点,那又是多么一件幸福和快乐的事情! |
|