Last post Aug 11, 2011 02:04 AM by Tamilmani Kpr
Aug 09, 2011 03:18 PM|ks123|LINK
I am trying to set properties to unlock User accounts in AD and I am using the following code; The problem is that de does not contain "userAccountControl" and the code fails. I can get the value of "userAccountControl" by using DirectorySearcher but that
does not help me in setting the property using de. Could anyone please help me? Thanks in advance
String m_Path="LDAP://" + distinguishedName;
Using(DirectoryEntry de= new DirectoryEntry(m_Path))
int m_Val = (int)de.Properties["userAccountControl"].Value ;
de.Properies["userAccountControl"].Value = m_Val | 0x0001
Aug 09, 2011 08:51 PM|gww|LINK
Its possible that the path may not be correct. Here is a good resrouce for many common AD scripts.
I think its better to use a directory searcher to locate the account with the samaccount name and if its found assign the search result to a directoryentry object and then modify its properties. That way you are sure you have the correct location of the
object each time. See this page here. About halfway down the page is an example of using directorysearcher to find a user and get its path.
Aug 11, 2011 02:04 AM|Tamilmani Kpr|LINK
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain,domainName);
UserPrincipal up = UserPrincipal.FindByIdentity(principalContext, IdentityType.DistinguishedName, userDn.Trim())