By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

Enable an user account using c#

P: n/a
Folks,

Here is the code I use in c# to enable an account. Everywhere I
looked it said this is the code, but it always gives me "Unspecified
error" on execution.Error happen when I am trying to assign updated
value back to the userflags property.

static void EnableUser(string strUser, string strDomain)
{
int ADS_UF_ACCOUNTDISABLE = 0x0002;
try
{
string strEntry = @"WinNT://" +
strDomain + "/" + strUser + ",
user";
System.DirectoryServices.DirectoryEntry
objUser = new
DirectoryEntry(strEntry);
int val = (int)
objUser.Properties["UserFlags"].Value;
val = val ^ ADS_UF_ACCOUNTDISABLE;
objUser.Properties["UserFlags"].Value =
val;
objUser.CommitChanges();
}
catch(Exception e)
{
objFS.WriteLine("Unable to unlock user
" + strUser);
objFS.WriteLine ("Exception encountered
" + e.Message);
}

}

Any help will be greatly appreciated.
Thanks!

Anil

May 12 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.