简体   繁体   English

如何在Active Directory中更改用户的登录名

[英]How to change login name of user in Active Directory

I want to change in my .NET application login of user from Active Directory. 我想从Active Directory更改用户的.NET应用程序登录。

I'm changing it in this way now: 我现在正以这种方式改变它:

DirectoryEntry userToUpdate = updatedUser.GetDirectoryEntry();  
userToUpdate.Properties["sAMAccountName"].Value = user.NewLogin;  
userToUpdate.CommitChanges();  

But it doesn't work as I expect. 但它没有像我期望的那样起作用。 When I'm checking in AD "Active Directory Users and Computers" entry for this user then on tab "account" I see that: 当我在为此用户检入AD“Active Directory用户和计算机”条目时,然后在“帐户”选项卡上,我看到:
- "User logon name" property isn't updated - “用户登录名”属性未更新
- "User logon name (pre-Windows 2000)" property is correcly updated. - “用户登录名(pre-Windows 2000)”属性已正确更新。

How to update correctly login name in AD from C# code? 如何从C#代码中正确更新AD中的登录名? What property should I set in DirectoryEntry, or there is another method to change login name. 我应该在DirectoryEntry中设置什么属性,或者有另一种方法来更改登录名。

There are two logon names in AD: AD中有两个登录名:

sAMAccountName    = User logon name, (pre-windows 2000) 
    Format/Usage: domain\user.name (note, your code will only populate user.name)

userPrincipalName = User logon name
    Format/Usage: user.name@domain.local

You need to update both. 您需要更新两者。

尝试使用userPrincipalName而不是sAMAccountName

Here is a really good link that you can reference be sure to checkout the bottom of the page to see it's full usage 这是一个非常好的链接,你可以参考一定要检查页面底部,看看它的完整用法

Everything in Active Directory via C#.Net 3.5 (Using System.DirectoryServices.AccountManagement) 通过C#.Net 3.5在Active Directory中的所有内容(使用System.DirectoryServices.AccountManagement)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM