Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


How to Rename a User in an AD Domain

Keywords: 	 rename user AD domain

Question:

I am using wntUserRename to rename a user in the domain. If I open the AD user and computers I see that only the login user will rename. how do I rename the display name?

Answer:

By referring to the "display name", are you referring to the user's full name, or are you referring to the name of their user object in Active Directory?

Either you might want...

wntUserSetDat("\\pdcname","test","full_name","test2",0)
which is what I think you want...

or is running in a "pure" ADSI installation (not mixed mode_ then you would have to use the ADSI extender and a whole different way of doing this. However since you can change somethings, then I think the proper wntUserSetDat command, as above, should work...

If you want to actually rename an object in Active Directory then you need to use the ADSI extender.

Resolution:

After researching the issue I found the best code for renaming a user in AD domain:
AddExtender("WWADS34I.DLL")
AddExtender("WWWNT34i.DLL")

;Change display name
errormode(@off)
sAdsiPath ="LDAP://server/cn=users,dc=domain,dc=com" 
dsSetCredent("domain\administrator", "password")
sEmpireGroup = dsFindPath(sAdsiPath , "CN=olduser")
dsSetProperty(sEmpireGroup, "givenname", "newuser")
dsSetProperty(sEmpireGroup, "userprincipalname", "newuser@domain.com")
dsSetProperty(sEmpireGroup, "displayname", "newuser")
sNewPath = dsMoveObj(sEmpireGroup, sAdsiPath, "cn=newuser")

;Check if change ok?
sEmpireGroup = dsFindPath(sAdsiPath , "cn=newuser")
slist = dsGetProperty(sEmpireGroup, "name")
if slist <> "newuser" then 
message("","error") 
else
message("","User renamed!") 
end if
errormode(@cancel)

;Change full name
wntUserSetDat("\\%server1%","olduser","full_Name","newuser",0)

;Change login name
wntUserRename("\\%server1%", "olduser", "newuser" ,0)