2011-09-08 53 views
0

我想要將用戶從一個OU移動到另一個OU,並使用System.DirectoryServices.Protocol更新一些屬性,但我很難找到任何除搜索外的任何其他代碼示例。System.DirectoryServices.Protocol移動用戶問題

任何人都可以發佈一些代碼示例和或鏈接到代碼示例/教程這兩個操作S.DS.P?

感謝,

校準 -

回答

1

下面是一個很好的C#的Active Directory實例源在Howto: (Almost) Everything In Active Directory via C#

//Move an object from one ou to another 
DirectoryEntry eLocation = new DirectoryEntry("LDAP://" + objectLocation); 
DirectoryEntry nLocation = new DirectoryEntry("LDAP://" + newLocation); 
string newName = eLocation.Name; 
eLocation.MoveTo(nLocation, newName); 
nLocation.Close(); 
eLocation.Close(); 

//Modify an attribute of a user object 

DirectoryEntry user = new DirectoryEntry(userDn); 
int val = (int)user.Properties["userAccountControl"].Value; 
user.Properties["userAccountControl"].Value = val & ~0x2; 
user.CommitChanges(); 
user.Close(); 
+0

是的,如果您使用System.DirectoryServices,這是一個很好的參考,但如果您使用的是System.DirectoryServices.Protocol,則不是。 S.DS =更容易,S.DS.P =更快唉我使用S.DS.P ... –