ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Sri Prab » Fri, 26 Oct 2001 17:52:11



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

Quote:}

catch(Exception e)

{

//do error handling

Quote:}

return true;

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

Thanks
Prabu

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Willy Denoyett » Fri, 26 Oct 2001 19:58:15


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.


> 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


 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Sri Prab » Fri, 26 Oct 2001 20:22:42


hi... thanks again.. for replying mail..
i did using cached credentials.. but i'm getting an exception with message
"Unknown error (0x80005000)"

Prabu


Quote:> 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.




Quote:> > 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
Quote:> > 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

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Willy Denoyett » Fri, 26 Oct 2001 20:30:43


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.


> hi... thanks again.. for replying mail..
> i did using cached credentials.. but i'm getting an exception with message
> "Unknown error (0x80005000)"

> Prabu



> > 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.



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

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Sri Prab » Fri, 26 Oct 2001 21:13:31


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;

        }

Quote:}

//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;

Quote:}

catch(Exception e)

    {

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

            return false;

    }

Quote:}

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Willy Denoyett » Sat, 27 Oct 2001 03:12:05



> 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)"

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.

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Sri Prab » Sat, 27 Oct 2001 17:11:01


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;

Quote:}

catch(Exception e)

{

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

return false;

Quote:}

thanks
Prabu


Quote:> 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
Quote:> 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

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Willy Denoyett » Sat, 27 Oct 2001 18:28:08



> 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};

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.

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Sri Prab » Sat, 27 Oct 2001 19:43:58


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





Quote:> > 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};

> 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
Quote:> account 'niceguy', in that case you should also set

AuthenticationTypes.Secure.
Quote:

> oDE = new DirectoryEntry(sDEPath,"niceguy",OldPassword,

AuthenticationTypes.Secure);

- Show quoted text -

Quote:

> Hope this helps.

> Willy.

 
 
 

ADSI DirectoryServices .NET beta 2 / C# Windows 2000 Server- Pro

Post by Willy Denoyett » Sun, 28 Oct 2001 01:57:39


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;


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

Willy.

 
 
 

1. C# + ADSI - DirectoryServices.dll + Window200 + .Net +

I could create an windows user, using DirectoryServices classes, after
creating the account, If I log out from my windows 2000 (professional), and
try to login with the new user that is created, it says no such account
exists, and I did check the active directory in the windows 2000 Advanced
server (where i'm creating the account) , the new user i have created is
there.
I guess I must be missing some properties while creating the user. Do you
have list of things (properties and values) to take care while creating a
user in the active directory (like permissions , user account control, user
account type) etc.

btw, I'm trying to login from the web application using my Login page, but
using the windows user account. If  I check the windows integrated and
uncheck the ananymous, it is throwing the login window, I don't want this
window, I would like to use my login page? do you know how to do this?

thanks
Prabu

2. Multi-session CD-ROM's

3. Uploading and retrieving picture from AD using C#, ASP .NET and System.DirectoryServices

4. FS - Applied Microsystems CodeICE 960Hx Emulator

5. LDAP, Exchange 5.5, .NET, C#, System.DirectoryServices, smtp address

6. Epson stylus color 600 printer

7. convert adsi vbs to directoryservices c#?

8. A3000 HD-problems...

9. Can't .NET do ADSI/LDAP/WinNT with DirectoryServices?

10. ADSI + ASP.NET (.NET Framework) System.Directoryservices

11. error with C# and .NET w/ADSI

12. Modify DENY Permissions in Exchange 2000 - Using C#/.NET ?????

13. windows Integrated Authentication without Popup window (.NET + ADSI)