When I create a single LDAP ActiveDirectory user and use
DirectoryEntry.Invoke("SetPassword"...), the user is created and the
password is set with no problems.
However, when I try to add more than one user by calling my CreateUser
method repeatedly, ADSI throws an exception when I try to set the
password of the second (and all subsequent) users I create. Does
anyone have a sense of why this is happening?
The error states that one or more input parameters are invalid, but if
I restart the program and use the same parameter for the password that
raised the exception in the previous run, no exception is thrown.
For example, if I use "u1" as user name and "p1" and password name for
the first user I create, and I use "u2" and "p2" for the second user,
when I call Invoke("SetPassword", object[]{"p2"}), I get the exception
below. However, if I restart the program and use "u2" and "p2" for the
first user I create, no exception is thrown.
Here is the error thrown.
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80005008): One or more
input parameters are invalid
Here is the method used to create the user.
internal void CreateUser(string userName, string password)
{
//GetRootEntries() gets the LDAP entries in the root group to which I
am adding users.
DirectoryEntries entriesRoot = GetRootEntries();
string userPathName = "cn=" + userName;
DirectoryEntry entryCheck = null;
DirectoryEntry entry = null;
try
{ // *** Seek previous entry with the same name. This
will throw an exception if user does not exist.
entryCheck = entriesRoot.Find(userPathName);
}
catch(Exception)
{
//user does not exist, which is what you want when
creating a user.
}
try
{
if ( entryCheck != null)
{
//user already exists
}
else
{
entry = entriesRoot.Add(userPathName, "user"
);
entry.Properties["sAMAccountName"].Add(userName);
entry.Properties["sn"].Add("User");
entry.Properties["givenName"].Add(userName);
entry.CommitChanges();
// User has to be saved prior to this step
entry.Invoke("SetPassword", new object[]
{password} );
// Create a normal account and enable it -
ADS_UF_NORMAL_ACCOUNT; this is part of Windows SDK
(ADS_USER_FLAG_ENUM)
// and to my knowledge, not part of .net. JL
12/18/03
entry.Properties["userAccountControl"].Value =
0x200;
entry.CommitChanges();
entry.Close();
//cleanup; this is required for AD to store
changes fully and completely.
entry.Dispose();
entry = null;
}
}
catch ( Exception e2)
{
//custom error handling here...
}
entriesRoot = null;
}
}
Thanks is advance for shedding light on this,
Jessica 2 11648
Jessica,
Make sure you bind securely when calling SetPassword, something like this
should work.....
....
// re-bind using a secure authentication type when calling SetPassword
using (DirectoryEntry userEntry = new DirectoryEntry(entry.Path,
bindUser,bindPwd,
AuthenticationTypes.Secure | AuthenticationTypes.ServerBind))
{
object[] password = new object[] {"somepassword"};
object ret = userEntry.Invoke("SetPassword", password );
userEntry.Properties["userAccountControl"].Value = 0x200;
userEntry.CommitChanges();
}
....
Willy.
"Jessica" <Je***************@ndchealth.com> wrote in message
news:5d**************************@posting.google.c om... When I create a single LDAP ActiveDirectory user and use DirectoryEntry.Invoke("SetPassword"...), the user is created and the password is set with no problems.
However, when I try to add more than one user by calling my CreateUser method repeatedly, ADSI throws an exception when I try to set the password of the second (and all subsequent) users I create. Does anyone have a sense of why this is happening?
The error states that one or more input parameters are invalid, but if I restart the program and use the same parameter for the password that raised the exception in the previous run, no exception is thrown.
For example, if I use "u1" as user name and "p1" and password name for the first user I create, and I use "u2" and "p2" for the second user, when I call Invoke("SetPassword", object[]{"p2"}), I get the exception below. However, if I restart the program and use "u2" and "p2" for the first user I create, no exception is thrown.
Here is the error thrown.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80005008): One or more input parameters are invalid
Here is the method used to create the user. internal void CreateUser(string userName, string password) { //GetRootEntries() gets the LDAP entries in the root group to which I am adding users. DirectoryEntries entriesRoot = GetRootEntries(); string userPathName = "cn=" + userName; DirectoryEntry entryCheck = null; DirectoryEntry entry = null;
try { // *** Seek previous entry with the same name. This will throw an exception if user does not exist. entryCheck = entriesRoot.Find(userPathName); } catch(Exception) { //user does not exist, which is what you want when creating a user. } try { if ( entryCheck != null) { //user already exists } else { entry = entriesRoot.Add(userPathName, "user" );
entry.Properties["sAMAccountName"].Add(userName); entry.Properties["sn"].Add("User"); entry.Properties["givenName"].Add(userName); entry.CommitChanges(); // User has to be saved prior to this step entry.Invoke("SetPassword", new object[] {password} );
// Create a normal account and enable it - ADS_UF_NORMAL_ACCOUNT; this is part of Windows SDK (ADS_USER_FLAG_ENUM) // and to my knowledge, not part of .net. JL 12/18/03 entry.Properties["userAccountControl"].Value = 0x200; entry.CommitChanges(); entry.Close(); //cleanup; this is required for AD to store changes fully and completely. entry.Dispose(); entry = null;
} } catch ( Exception e2) { //custom error handling here... } entriesRoot = null; } }
Thanks is advance for shedding light on this, Jessica
Willy,
I have a few questions. How will binding securely solve
the problem I posted? Why do you think I am seeing the
error "One or more input parameters are invalid"?
Second, after you create a user and before you have set
the password, what value do you use for the password when
creating a new DirectoryEntry? I tried creating a new
DirectoryEntry as you suggested, using string.Empty as
the password, thinking this would be the correct value
before the password was ever set on the entry, but when I
tried to set the password, I got the exception "Logon
failure: unknown user name or bad password".
Thanks,
Jessica -----Original Message----- Jessica,
Make sure you bind securely when calling SetPassword,
something like thisshould work.....
.... // re-bind using a secure authentication type when
calling SetPassword using (DirectoryEntry userEntry = new DirectoryEntry
(entry.Path,bindUser,bindPwd, AuthenticationTypes.Secure |
AuthenticationTypes.ServerBind)) { object[] password = new object[] {"somepassword"}; object ret = userEntry.Invoke("SetPassword",
password ); userEntry.Properties["userAccountControl"].Value =
0x200; userEntry.CommitChanges(); } ....
Willy.
"Jessica" <Je***************@ndchealth.com> wrote in
messagenews:5d**************************@posting.google. com... When I create a single LDAP ActiveDirectory user and
use DirectoryEntry.Invoke("SetPassword"...), the user is
created and the password is set with no problems.
However, when I try to add more than one user by
calling my CreateUser method repeatedly, ADSI throws an exception when I try
to set the password of the second (and all subsequent) users I
create. Does anyone have a sense of why this is happening?
The error states that one or more input parameters are
invalid, but if I restart the program and use the same parameter for
the password that raised the exception in the previous run, no exception
is thrown. For example, if I use "u1" as user name and "p1" and
password name for the first user I create, and I use "u2" and "p2" for
the second user, when I call Invoke("SetPassword", object[]{"p2"}), I
get the exception below. However, if I restart the program and use "u2"
and "p2" for the first user I create, no exception is thrown.
Here is the error thrown.
System.Reflection.TargetInvocationException: Exception
has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException
(0x80005008): One or more input parameters are invalid
Here is the method used to create the user. internal void CreateUser(string userName, string
password) { //GetRootEntries() gets the LDAP entries in the root
group to which I am adding users. DirectoryEntries entriesRoot = GetRootEntries(); string userPathName = "cn=" +
userName; DirectoryEntry entryCheck = null; DirectoryEntry entry = null;
try { // *** Seek previous entry with the
same name. This will throw an exception if user does not exist. entryCheck = entriesRoot.Find
(userPathName); } catch(Exception) { //user does not exist, which is
what you want when creating a user. } try { if ( entryCheck != null) { //user already exists } else { entry = entriesRoot.Add
(userPathName, "user" );
entry.Properties["sAMAccountName"].Add(userName); entry.Properties["sn"].Add
("User"); entry.Properties
["givenName"].Add(userName); entry.CommitChanges(); // User has to be saved prior
to this step entry.Invoke("SetPassword",
new object[] {password} );
// Create a normal account and
enable it - ADS_UF_NORMAL_ACCOUNT; this is part of Windows SDK (ADS_USER_FLAG_ENUM) // and to my knowledge, not
part of .net. JL 12/18/03 entry.Properties
["userAccountControl"].Value = 0x200; entry.CommitChanges(); entry.Close(); //cleanup; this is required
for AD to store changes fully and completely. entry.Dispose(); entry = null;
} } catch ( Exception e2) { //custom error handling here... } entriesRoot = null; } }
Thanks is advance for shedding light on this, Jessica
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Lekyan |
last post by:
I have problem setting the password for an ADAM user using C#. I used
the SetPassword code given in the Microsoft page, changed several
parameters, but ran into an exception. I wonder if other...
|
by: Vikash Kumar Mitruka |
last post by:
Hi,
While Invoking the SetPassword to reset the passowrkd of user in AD, i
m getting the following error
Exception Occurred at the target of Invocation
Inner Exception -- {"The network path...
|
by: knea |
last post by:
Hi,
I noticed a bunch of postings about getting error while invoking the
"setPassword" method. I am getting similar error and any help would
be appreciated. The error that I am getting is:
...
|
by: Marek Kopanski |
last post by:
Hallo,
I have to change a user password in my ASP.NET project.
In the first step I was trying to change my own passwort (as example) in
Active Directory on my Server, but already at this point I...
|
by: Mike |
last post by:
I am trying to enumerate the webs on a remote server
using the DirectoryEntry provider for VB.NET. Here is my
code:
Try
Dim SelNode As String =
TreeConfig.SelectedNode.Text
Dim oSite As...
|
by: ABSMunkee |
last post by:
I have a vb.net dll that has two functions: one allows a user to change
their password in AD, the second allows the user to view their
distinguishedname (based on their samaccountname). Both bind...
|
by: somebody |
last post by:
Hi there
I am using VB2005 come up with a small app to reset the user's password in
a 2000 AD. I have am able to create the user's account but all fails when I
try to set the initial password....
|
by: Magnus R |
last post by:
In VB.Net I'm trying to find out the names of what Administrative Groups
exist by querying Active Directory. The problem is when I try and query the
children of the key LDAP://CN=Administrative...
|
by: Michael Howes |
last post by:
I'm writing a utility to manage a machines *local* accounts in c#
I am getting all the users in a specific Group just fine but when I
want to get some of the information on each user from their...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |