Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am tying to set password for user in active directory using VB.NET. The Active Directory is in another server. I am getting error as Inner Exception: "{"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}". If u know please help me on it. Thank you.

objUser.Invoke("SetPassword", strNewPassword) this line only throwing an error.

objDe = New DirectoryEntry(Pathweb)

cobjDS = New DirectorySearcher(objDe)
VB
cobjDS.Filter = "(&" + str_USER + "(" + str_SEARCH + UserId + "))"

            Dim objSearchResult As SearchResult = cobjDS.FindOne()

            Dim objUser As DirectoryEntry = objSearchResult.GetDirectoryEntry()
            objUser.Invoke("SetPassword", strNewPassword)



I am able to do it in C#. But it required ADS server Admin username and password. Is there any way to do in VB.Net.
The C# code is.

C#
PrincipalContext PrincipalContext = new PrincipalContext(ContextType.Domain, ADSServerIP, userpath, ContextOptions.Negotiate, ADSadminuser, ADSadminPSW);
UserPrincipal User = UserPrincipal.FindByIdentity(PrincipalContext, userid);
User.SetPassword(newpassword);
Posted
Updated 5-Dec-13 19:57pm
v2

You need to be member of administrator group in Domain to be able to change the password of users. If you do have the login details of Administrator of the domain, try log in to your system using the administrator credentials and run the application again. Access Denied error should go now
 
Share this answer
 
Comments
ssyuvaraja 6-Dec-13 1:34am    
Hi, Thank you. I am login as administrator only. Still getting same error.
ssyuvaraja 6-Dec-13 1:53am    
I am able to set password using C#. But by giving ADS server admin user name and password. Is there any way to do it in VB.net.
PrincipalContext PrincipalContext = new PrincipalContext(ContextType.Domain, ADSServerIP, userpath, ContextOptions.Negotiate, ADSadminuser, ADSadminPSW);
UserPrincipal User = UserPrincipal.FindByIdentity(PrincipalContext, userid);
User.SetPassword(newpassword);
Hi,
I changed the password using Old password. I am not used the Set password this time. I used the change password. It worked. in C#.

C#
PrincipalContext PrincipalContext = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["ADSServerIP"].ToString(), usertype);
            UserPrincipal User = UserPrincipal.FindByIdentity(PrincipalContext, userid);
            User.ChangePassword(strOldPassword, newpassword);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900