c# - Why is User.Invoke("SetPassword") using my computer's current credentials and how I can I specify them instead? -
i able create new users in remote activedirectory server, doing using admin account on server. how that:
string connection = "ldap://serveraddress/ou=newusers,ou=people,dc=mydomain,dc=local"; usersdirectoryentry = new directoryentry(connection, "adminusername","adminpass"); directoryentry newuser = usersdirectoryentry.children.add(userstring, "user"); newuser.commitchanges();
however, after trying set password using:
updatepassword(newuser, "userpasswordmeetsrequirements");
where
private static void updatepassword(directoryentry user, string password) { user.properties["pwdlastset"].value = -1; user.invoke("setpassword", new object[] { password.trim() }); user.properties["useraccountcontrol"].value = 0x0200 | 0x10000; user.commitchanges(); }
where user of type directoryentry (https://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry(v=vs.110).aspx)
and on user.invoke line system.reflection.targetinvocationexception --> system.unauthorizedaccessexception: access denied.
that admin user should indeed have set password permissions. after looking in ad logs found @ user.invoke line program trying connect ad server using current credentials on computer (which on different domain).
why happening, , how can force use admin account used user creation?
are passing newuser object updatepassword? assume it's using same credentials.
but if not, can create new object this:
var user = new directoryentry(newuser.path, "adminusername","adminpass"); updatepassword(user, somepassword);
Comments
Post a Comment