473,698 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Change password in AD

2 New Member
I am trying to change the Active Directory password using C#. However, it seems to me it does not really works. I wonder what is wrong with my code. Hope somene can help me with this and thanks in advance. Below is my code :


try
{
string dcDNS = "mypsptestd ev"; //use this if you want to supply a server name
DirectoryEntry userEntry = null;
string currentUserName = (((string)Conte xt.User.Identit y.Name).Split(' \\')) [1];

DirectoryEntry rootDSE = new DirectoryEntry( String.Format(" LDAP://{0}/rootDSE", dcDNS), "_aduser", "TESTsql@dm 1n", AuthenticationT ypes.Secure);

string rootDN = rootDSE.Propert ies["defaultNamingC ontext"].Value.ToString ();

DirectoryEntry searchRoot = new DirectoryEntry( String.Format(" LDAP://{0}/{1}", dcDNS, rootDN), "_aduser", "TESTsql@dm 1n", AuthenticationT ypes.Secure);

DirectorySearch er searcher = new DirectorySearch er(searchRoot);
searcher.Filter = String.Format(" samAccountName= {0}", "_aduser");
searcher.Search Scope = SearchScope.Sub tree;

SearchResultCol lection results = searcher.FindAl l();

foreach (SearchResult result in results)
{
userEntry = result.GetDirec toryEntry();
break;
}

if (userEntry == null)
{
throw new InvalidOperatio nException("Use r not found in this domain.");
}

userEntry.Invok e("ChangePasswo rd", new object[]{"TESTsql@dm1n" , "sql@dm1n"} );
userEntry.Commi tChanges();
}

catch (System.Reflect ion.TargetInvoc ationException ex)
{
Response.Write( "msg1 = " + ex.ToString() + "<br>");
Response.Write( "msg2 = " + ex.InnerExcepti on.ToString());
}



And this is the error i got :

System.Reflecti on.TargetInvoca tionException: Exception has been thrown by the target of an invocation. ---> System.Runtime. InteropServices .COMException (0x8007202F): A constraint violation occurred. --- End of inner exception stack trace --- at System.RuntimeT ype.InvokeDispM ethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters ) at System.RuntimeT ype.InvokeMembe r(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifi er[] modifiers, CultureInfo culture, String[] namedParameters ) at System.Type.Inv okeMember(Strin g name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Director yServices.Direc toryEntry.Invok e(Str ing methodName, Object[] args) at AdminChangePass wd.test.ChangeP assword1() in c:\portal administration\ adminchangepass wd\test.aspx.cs :line 246
System.Runtime. InteropServices .COMException (0x8007202F): A constraint violation occurred.
Apr 10 '06 #1
0 5191

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2410
by: MLH | last post by:
What's the simplest way to allow a user of an A97 app to change password?
10
9871
by: Fabrizio | last post by:
(Sorry for the crosspost, but I really don't know which is the right newsgroup!) Hi all, I try to change the password to a user that as to change the password at first logon: try {
0
3668
by: GregS | last post by:
We have a client that has a very large number of users that will be connecting back to the domain via VPN only. The problem is that the communications vendor can not pass the password expiration notice back to the client. What we would like to do is run a script or application after the vpn tunnel is established that checks the number of days remaining before the password expires and then give the user a prompt to change their password when a...
6
5141
by: Jan | last post by:
Hi: I have created a secured database for a client. For various reasons, I don't want the client to have full persmissions for the database; they aren't in the admins group. I have instead tried to create a second group, called "localAdmin," for the admin-type person at the client. I want this group to be able to do some basic admin-type stuff, including adding new users and clearing passwords if users forget theirs. I can't seem to...
2
4494
by: J | last post by:
Hello. I apologize if this isn't the appropriate group for this question but I was wondering if it's possible to allow regular windows domain users to change their passwords through an .asp page? I'm trying to figure out the best way to handle domain users to log into an .asp application tied with SQL Server 2000 on the back end since I keep reading that windows authentication is better practice to log into SQL Server. Thanks in...
1
6056
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while during the runtime, the user can click on a button and change the connection string without exiting the application. I would really appreciate any sort of help.
3
7936
by: W C Hull | last post by:
We have a request from Auditing to modify the password an a local workstation administrative account every 90 days. We are developing two programs - a VB6 GUI program that will allow the administrative support person to enter a new password into an App and have that encrypted password saved in a text file. The second part is a VB6 program that only is a command line program that will open the password text file, read the encrypted...
1
2321
by: eighthman11 | last post by:
Hi everyone: I created a custom toolbar called Password, so users can change their password. I used the Command "User and Group Accounts". I know the user can not change anything in the Tab "Users" or "Groups" in the "User and Group Accounts" and can only use the tab "Change Logon Password", but can I force a tab selection to the tab "Change Logon Password" and disable the other two tabs? Or does anyone know of an alternative way to...
0
2209
by: shellegreen | last post by:
Hello, I need help with some password changes that I have to do in some iPAQs. The company that I work has 3 models of iPAQ and 3 different versions of Windows Mobile (Microsoft Pocket PC 4.20.0, Win Mobile 2003 SE e Win Mobile 5.0). The devices are configured to use Dial up or Cell Phone connection (Bluetooth or infrared). Recently we developed a program that check the user password expiration date in Active Directory Server every...
2
5072
by: bemytthm | last post by:
I just want to ask abt communicate with AD using ASP.net. I would want to ask you all to help me correct a problem like this: This is a code i use to change password on AD public bool ChangePasswordAD(string strLogin, string strOldPasswd, string strNewPasswd) { try { string domainAndUsername = "aloha.com" + @"\" + strLogin; DirectoryEntry entry = new...
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.