Невозможно создать пользователя на Windows Server 2008 из-за разрешения доступа
Я получаю ниже ошибку при попытке создать пользователя на удаленном компьютере.
System.UnauthorizedAccessException: общая ошибка запрещена в доступе в System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.GetInfo() в System.DirectoryServices.DirectoryEntry.RefreshCache() в System.DirectoryServices.AccountManagement.PrincipalContext.MacDirectory.MacDirectory.MacDirectory.MacDirectory.MacDirectory.Server..PrincipalContext.Initialize () в System.DirectoryServices.AccountManagement.PrincipalContext.ContextForType(Type t) в System.DirectoryServices.AccountManagement.Principal.GetStoreCtxToUse() в System.DirectoryServices.TackSystemWindows_setupID (Строковое имя пользователя, Строковый пароль, Строка displayName, Строковое описание, Boolean canChangePwd, Boolean pwdExpires)
вот код
public void CreateLocalWindowsAccount(string username, string password, string displayName, string description, bool canChangePwd, bool pwdExpires)
{
try
{
PrincipalContext context = new PrincipalContext(ContextType.Machine, "127.0.0.1");
UserPrincipal user = new UserPrincipal(context);
user.SetPassword(password);
user.DisplayName = displayName;
user.Name = username;
user.Description = description;
user.UserCannotChangePassword = canChangePwd;
user.PasswordNeverExpires = pwdExpires;
user.Save();
//now add user to "Users" group so it displays in Control Panel
GroupPrincipal group = GroupPrincipal.FindByIdentity(context, "Remote Desktop Users");
group.Members.Add(user);
group.Save();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}