When you're writing a development related blog, you're eventually (hopefully) going to write some code snippets that you want to share with your readers. However, in order to get the most out of that code snippet, you should make it easy to read and color coded so that potential users can quickly read through your code and evaluate its worth.
That's where CopySourceAsHTML will solve all your problems. CSAH is a plug-in that integrates directly into your Visual Studio IDE environment and allows you to highlight code, right click and choose "Copy As HTML". The tool is freeware and performs exceptionally - if you maintain a .Net developer blog, I would suggest installing this add-on.
How to Unlock a Domain Account in Active Directory utilizing C# .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):
...
private void btnDisableUser_Click(object sender, System.EventArgs e)
{
string strUserName = "InsertUserNameHere";
DirectoryEntry usr = new DirectoryEntry("LDAP://dc=InsertDomainHere, dc=COM");
DirectorySearcher searcher = new DirectorySearcher(usr);
searcher.Filter = "(SAMAccountName=" + strUserName + ")";
searcher.CacheResults = false;
SearchResult result = searcher.FindOne();
usr = result.GetDirectoryEntry();
usr.Properties["LockOutTime"].Value = 0x0000;
usr.CommitChanges();
}
How to Disable a Domain Account in Active Directory utilizing C# .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):
...
private void btnDisableUser_Click(object sender, System.EventArgs e)
{
string strUserName = "InsertUserNameHere";
DirectoryEntry usr = new DirectoryEntry("LDAP://dc=InsertDomainHere, dc=COM");
DirectorySearcher searcher = new DirectorySearcher(usr);
searcher.Filter = "(SAMAccountName=" + strUserName + ")";
searcher.CacheResults = false;
SearchResult result = searcher.FindOne();
usr = result.GetDirectoryEntry();
usr.Properties["userAccountControl"].Value = 0x0002;
usr.CommitChanges();
}
Below are code samples utilizing C# .Net. If you have any questions, comments or corrections on any code sample, please email me at "hagrin at gmail dot com" (email written out to avoid email harvesters) and I'll try and get back to all user inquiries as soon as possible. Thank you and hopefully this code will prove to be helpful.
Disable a Domain Account in Active Directory
Unlock a Domain Account in Active Directory
Recent Comments
3 weeks 2 days ago
3 weeks 3 days ago
5 weeks 4 days ago
7 weeks 4 days ago
1 year 13 weeks ago
1 year 13 weeks ago
1 year 14 weeks ago
1 year 15 weeks ago
1 year 18 weeks ago
1 year 19 weeks ago