Multimobile Development: Building Applications for any Smartphone
ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Sri Prabu
After creating the account successfully, When I try to change the
password, I get the exception message - Network path not found

----------------------------------------------------------------------------

try
{
string sDEPath = cLDAP + mPDC + "/CN=" + LoginId + ",CN=Users," +
mDomainContext;

/// "*** sDEPath =
LDAP://172.25.200.25:389:/CN=myusername,CN=Users,DC=myservername,DC=psi,DC=s
oft,DC=net

DirectoryEntry oDE = new
DirectoryEntry(sDEPath,LoginId,OldPassword,AuthenticationTypes.Secure);

object[] oPassword = new object[] {NewPassword};

/// Calls the 'SetPassword' object's method
///using IADsUser.Invoke (IDispatch method).
object oRet = oDE.Invoke("setPassword", oPassword );

///********** in the last statement I'm getting an exception thrown saying:
Network path not found.
/// I did check the sDEPath to retreive the other properties using
///

///********* of the user, thatz working fine.
oDE.CommitChanges(); // calls IADsUser.SetInfo to persist the changes

}

catch(Exception e)

{

//do error handling

}

return true;

----------------------------------------------------------------------------

Thanks
Prabu

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Willy Denoyette (VIP)
Try binding to the AD using cached credentials like:

.......

DirectoryEntry userEntry = new DirectoryEntry(UserPath, strUsername, null); // using cached credentials
object[] password = new object[] {"yoursecret"};
object ret = userEntry.Invoke("SetPassword", password );
userEntry.CommitChanges();

Willy.

"Sri Prabu" <Click here to reveal e-mail address> wrote in message news:eYTG1ITXBHA.2020@tkmsftngp07...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Sri Prabu
hi... thanks again.. for replying mail..
i did using cached credentials.. but i'm getting an exception with message
"Unknown error (0x80005000)"

Prabu

"Willy Denoyette" <Click here to reveal e-mail address> wrote in message
news:e1DjyRUXBHA.1480@tkmsftngp03...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Willy Denoyette (VIP)
That means no credentials available, what is the context of this application (asp.net or anything else).
Did you bind to the AD prior to setting the password?
Maybe the rest of the code would help.

Willy.

"Sri Prabu" <Click here to reveal e-mail address> wrote in message news:e9qLucUXBHA.432@tkmsftngp07...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Sri Prabu
I have attached the code that I use.
The create user as follows: It is creating the user successfully. and I'm
able to log on with the new user created through my application, and when i
log on for the first time it asks for the change password.
but when I try to set password through my application it fails. I get an
exception with an exception saying : "Unknown error (0x80005000)"

Thanks
Prabu
//this function will change the password

public bool ChangePassword(string LoginId,string OldPassword,string
NewPassword)

{

//Constants

const string cMETHOD_NAME="ChangePassword";

if(mDomainContext == "")

{

if (!this.SetDefaultDomainContext()) /// get the
default domain context which will set the mDomainContext's value

{

return false;

}

}

if(LoginId == null || LoginId == "")

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Login Id
Missing");

return false;

}

/// Old password and New password are checked for NULL , if so this
funtion returns false.

try

{

string sDEPath = cLDAP + mPDC + "/CN=" + LoginId + ",
CN=Users," + mDomainContext; /// Constant cLDAP = "LDAP://", mPDC is set
by the user

DirectoryEntry oDE = new
DirectoryEntry(sDEPath,LoginId,OldPassword);

object[] oPassword = new object[] {NewPassword};

object oRet = oDE.Invoke("setPassword", oPassword ); // Calls
the 'SetPassword' object's method using IADsUser.Invoke (IDispatch method).

oDE.CommitChanges(); // calls IADsUser.SetInfo to persist the
changes

return true;

}

catch(Exception e)

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Change Password
Failed",e);

return false;

}

}

//this function creates a new user in the ActiveDirectory.

public bool CreateUser(UserInfo NewUser)

{

//Constants

const string cMETHOD_NAME="CreateUser";

//Variables

DirectoryEntry oDE;

DirectoryEntry oDEC;

if(mDomainContext == "")

{

if (!this.SetDefaultDomainContext())

{

return false;

}

}

if(mPDC == null || mPDC =="")

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Primary Domain
Controler Not Set");

return false;

}

if(NewUser.LoginId == null || NewUser.LoginId == "")

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Login Id Missing");

return false;

}

if(NewUser.AccountName == null || NewUser.AccountName == "" )

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Account Name
Missing");

return false;

}

try

{

oDE = new DirectoryEntry();

oDE.Path= cLDAP + mPDC + "/CN=Users," + mDomainContext;

oDE.Username = mADSAdminUser;

oDE.Password = mADSAdminPass;

oDE.AuthenticationType = AuthenticationTypes.Secure;

oDEC = oDE.Children.Add("CN=" +
NewUser.LoginId.ToString(),cAD_USER_CLASS.ToString());

oDEC.Properties[cAD_sAM_ACCOUNT_NAME].Add(NewUser.AccountName);

//the other one i tried with 66048, but it justs creats the user
with password never expries still i couldn't set the password

oDEC.Properties[cAD_USER_ACCOUNT_CONTROL].Add("512");

oDEC.Properties[cAD_USER_NAME].Add(NewUser.AccountName);

oDEC.Properties["userPrincipalName"].Add(NewUser.AccountName);

if(NewUser.DisplayName != "")

{

oDEC.Properties[cAD_DISPLAY_NAME].Add(NewUser.DisplayName);

}

if(NewUser.FirstName != "")

{

oDEC.Properties[cAD_GIVEN_NAME].Add(NewUser.FirstName);

}

if(NewUser.LastName != "")

{

oDEC.Properties[cAD_SUR_NAME].Add(NewUser.LastName);

}

if(NewUser.Email != "")

{

oDEC.Properties[cAD_MAIL].Add(NewUser.Email);

}

/* Need to consider whether to set "UserPassword" or not */

/***************** Commented it out since i found no use of it

if(NewUser.Password != "")

{

oDEC.Properties[cAD_USER_PASSWORD].Add(NewUser.Password);

}

else

{

oDEC.Properties[cAD_USER_PASSWORD].Add(NewUser.LoginId);

}

******************/

oDEC.CommitChanges();

//////////////// Set the default password for the user once
it is created. but here while executing the Invoke method

//////////////// it throws an exception with Message
"Exception has been thrown by the target of an invocation." string
//////////////// message NETWORK PATH NOT FOUND in the inner
exception.

//by default use account name as its password

object[] oPassword = new object[] {NewUser.AccountName};

// Calls the 'SetPassword' object's method using IADsUser.Invoke
(IDispatch method).

object oRet = oDEC.Invoke("setPassword", oPassword );

// calls IADsUser.SetInfo to persist the changes

oDEC.CommitChanges();

return true;

}

catch(Exception e)

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Create User
Failed",e);

return false;

}

}

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Willy Denoyette (VIP)
"Sri Prabu" <Click here to reveal e-mail address> wrote in message news:eHSHL5UXBHA.1440@tkmsftngp07...
[Original message clipped]

I guess you are binding using the credentials ( LoginId,OldPassword) of the newly created user, unless this user is a member of the
administrators group AND has been granted the rights to 'reset a users password', you cannot invoke 'setPassword' using this
account.

< your code----
DirectoryEntry oDE = new
DirectoryEntry(sDEPath,LoginId,OldPassword);
>
Instead you should invoke 'ChangePassword', but then again the user must have the rights to change his/her own password.

Something like this so work:

object[] password = new object[] {"oldpassword", "newSecret"};
object ret = xxxx.Invoke("ChangePassword", password );

Willy.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Sri Prabu
I'm getting an Exceptoin with the following message:
Message "Configuration information could not be read from the domain
controller, either because the machine is unavailable, or access has been
denied." string

I created a new user, with the permissions to change the password, I did
logon from my machine windows 2000 (pro) to the server, with the newly
created user and i changed the password it worked fine.
But I got the above exception when i tried to change the password from my
application.:(

try

{

string sDEPath = cLDAP + mPDC + "/CN=" + LoginId + ",CN=Users," +
mDomainContext;

oDE = new DirectoryEntry(sDEPath,LoginId,OldPassword);

object[] oPassword = new object[] {OldPassword,NewPassword};

object oRet = oDE.Invoke("changePassword", oPassword ); // Calls the
'SetPassword' object's method using IADsUser.Invoke (IDispatch method).

oDE.CommitChanges(); // calls IADsUser.SetInfo to persist the changes

return true;

}

catch(Exception e)

{

mError.SetErrorInfo(cCLASS_NAME,cMETHOD_NAME,"Change Password Failed",e);

return false;

}

thanks
Prabu

"Sri Prabu" <Click here to reveal e-mail address> wrote in message
news:eYTG1ITXBHA.2020@tkmsftngp07...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Willy Denoyette (VIP)
"Sri Prabu" <Click here to reveal e-mail address> wrote in message news:eugkTWfXBHA.1388@tkmsftngp07...
[Original message clipped]

I suppose "LoginID" is the logon name of the newly created user, and the
> oDE = new DirectoryEntry(sDEPath,LoginId,OldPassword);
call is the first bind in your application.

In that case you need to prepend the name with domainname\
ex.
Suppose your domain name is : 'MyDomain' and the user is 'niceguy'

the constructor call should look like:

oDE = new DirectoryEntry(sDEPath,"MyDomain\\niceguy",OldPassword);

Another possibility is to use a null session, in that case 'niceguy' must be a local account with the same password as the domain
account 'niceguy', in that case you should also set AuthenticationTypes.Secure.

oDE = new DirectoryEntry(sDEPath,"niceguy",OldPassword, AuthenticationTypes.Secure);

Hope this helps.

Willy.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Sri Prabu
I'm working on a Windows 2000 Proffessional edition(my machine ), which is
working under a the windows 2000 advanced server, domain controller (Server
Machine).
I created a new user, user logon name : 1000 and password : 1000
the new user created, is a member of Domain users.
So i need to prefix with the Domain name while changing the password.
I run my program with both prefixing with the domain name and also passing
the authenticationtypes.secure
both failed and gave the same error message.
"Configuration information could not be read from the domain controller,
either because the machine is unavailable, or access has been denied."

Then I logged off from my machine (my user account in the same domain)and
logged in using the new user created (1000 ), it logged in perfectly.

I'm missing something, must be a simple mistake i'm comming, I wonder where
I'm lost.

thanks
Prabu

"Willy Denoyette" <Click here to reveal e-mail address> wrote in message
news:eIbAGEgXBHA.1496@tkmsftngp05...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Willy Denoyette (VIP)
It looks like you are binding using the same user credentials as the newly created user (variable LoginId).
Well if this is true, you have to understand that unless you included this user to a domain admins group, the user belongs to the
domain users group.
This group has no rights to ChangePassword nor to SetPassword.

Could you try using domain\administrator to bind to the AD.
like:

string sDEPath = cLDAP + mPDC + "/CN=" + LoginId + ",CN=Users," +
mDomainContext;

oDE = new DirectoryEntry(sDEPath,@"YourDomain\administrator" ,"AdminPassword");

object[] oPassword = new object[] {OldPassword,NewPassword};

Willy.

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.DirectoryServices.AuthenticationTypes
System.DirectoryServices.DirectoryEntry






Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Copyright © AMX Software Ltd 2008-2012. Portions copyright © Matthew Baxter-Reynolds 2001-2012. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734

Hi! 10 years ago I founded .NET 247. I am working on a new and exciting replacement for the site. Please join me on Twitter to discuss.

Thanks,
Matthew Baxter-Reynolds (@mbrit)

Follow mbrit on Twitter