我想更改远程计算机用户帐户的密码 .
我是这样做的:
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 = Access被拒绝 . Source = System.DirectoryServices ErrorCode = -2147024891 StackTrace:System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)位于System.DirectoryServices.DirectoryEntry.Bind()的System.DirectoryServices.DirectoryEntry.RefreshCache()处于System.DirectoryServices.AccountManagement . System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context,Type principalType,Nullable`1 identityType)的System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()处的PrincipalContext.DoMachineInit() ,String identityValue,DateTime refDate)at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context,String identityValue)InnerException:
将PrincipalContext与没有密码保护的帐户一起使用是否有一些限制?如何为没有设置任何当前密码的远程计算机用户帐户设置密码?
1 回答
远程登录具有空白密码的帐户是有限制的 .
您是否在本地运行脚本以更改密码,但您可以使用psexec运行“本地”脚本 .
解:
1)编写一个更改本地用户密码的脚本
2)使用psexec从远程计算机运行脚本
远程计算机必须具有管理用户帐户和密码,否则您无法远程登录 .