【问题标题】:Change password for remote machine User Account that has "current password = empty"更改具有“当前密码 = 空”的远程计算机用户帐户的密码
【发布时间】:2013-05-23 14:45:11
【问题描述】:

我想更改远程机器用户帐户的密码。

我正在这样做:

PrincipalContext context = new PrincipalContext(ContextType.Machine, "xxx.xxx.xxx.xxx" /*Remote machine IP address*/, "RemoteAdminUserName", "RemoteAdminPassword");
UserPrincipal user = (UserPrincipal.FindByIdentity(context, "RemoteAdminUserName"));
user.SetPassword("RemoteAdminNewPassword");
user.Save();

此代码正常工作,除非我尝试将密码设置为旧密码为空的帐户。 在那种情况下,我在UserPrincipal.FindByIdentity 中有以下异常

System.Runtime.InteropServices.COMException 未处理 Message=访问被拒绝。

Source=System.DirectoryServices 错误代码=-2147024891 堆栈跟踪: 在 System.DirectoryServices.DirectoryEntry.Bind(布尔 throwIfFail) 在 System.DirectoryServices.DirectoryEntry.Bind() 在 System.DirectoryServices.DirectoryEntry.RefreshCache() 在 System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit() 在 System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() 在 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() 在 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext 上下文,类型 principalType,Nullable`1 identityType,字符串 identityValue,DateTime refDate) 在 System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext 上下文,字符串 identityValue) 内部异常:

在没有密码保护的帐户中使用 PrincipalContext 是否有一些限制? 如何为未设置任何当前密码的远程计算机用户帐户设置密码?

【问题讨论】:

    标签: c# active-directory remote-access account directoryservices


    【解决方案1】:

    使用空白密码远程登录帐户存在限制。

    您可以在本地运行脚本来更改密码,但您可以使用 psexec 运行“本地”脚本。

    解决方案:

    1) 编写一个修改本地用户密码的脚本

    2) 使用 psexec 从远程计算机运行脚本

    远程计算机必须具有带密码的管理用户帐户,否则您无法远程登录。

    【讨论】:

    • 谢谢,这是一个很好的解决方案!我会在接下来的几天内尝试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    • 2023-01-05
    • 2021-04-01
    相关资源
    最近更新 更多