473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Enable an user account using c#

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
0 1093

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: John | last post by:
Hello. I want to get this blasted .htaccess file sorted out, so I can have sessions without register_globals being on. I have looked everywhere for info on this and I mean everywhere...
4
by: Dan Avni | last post by:
I have a site that has been working for a few years now. the web site is using a DB Access DLL written in VB. the DB's connection string is passed to the DLL using the COM+ enable object...
1
by: Angelo | last post by:
Hi, I've been trying to create a user in Active Directory. So far this works, however default the user is disabled. I've been trying so much code to enable the user, but without success, perhaps...
10
by: John Bunch | last post by:
I have installed Visual Studio 2005 Team Suite Beta 2, including SQL Server 2005 Express Edition April CTP, on Windows XP Professional SP2, including IIS 5.1. The SQL Server (SQLEXRPESS) service...
4
by: Sheldon Penner | last post by:
I have been working my way through an ASP.NET tutorial and I find that any code that attempts to update an Access table evokes the error: "Operation must use an updateable query." A search of...
1
by: Jeremie Legault | last post by:
Hi, I have written an ASP.NET 2.0 application that uses Active Directory or ADAM to manage account users - the site has a page that allows people to create an account (much like any site). The...
0
by: Jeremie Legault | last post by:
Hi, I have written an ASP.NET 2.0 application that uses Active Directory or ADAM to manage account users - the site has a page that allows people to create an account (much like any site). The...
0
by: Vear | last post by:
Hi, I looking for the method to disable and enable user accounts. I want the user to have to validate their account via email. I have all of the email stuff working but I can't figure out how in...
3
by: Michael Howes | last post by:
This MSDN article http://msdn2.microsoft.com/en-us/library/ms180913(vs.80).aspx and this codeproject article http://www.codeproject.com/useritems/everythingInAD.asp both show the same c# code...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.