Домой User Создание локальных пользователей: Справочник по C#

Создание локальных пользователей: Справочник по C#

506
0


/// 
/// method to create a new local Windows user account
/// 
/// Username of the new account/// Password of the new account/// Account display name/// Account description/// Value of whether the new user can change their password/// Value determining if the password ever expirespublic static bool CreateLocalWindowsAccount(string username, string password, string displayName, string description, bool canChangePwd, bool pwdExpires)
{
try
{
PrincipalContext context = new PrincipalContext(ContextType.Machine);
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, "Users");
group.Members.Add(user);
group.Save();

return true;
}
catch (Exception ex)
{
MessageBox.Show("Error creating account: {0}", ex.Message);
return false;
}
}

Взято с http://www.dreamincode.net

ЧИТАТЬ ТАКЖЕ:  Проверка прав администратора у пользователя на локальной ПЭВМ: Справочник по C#

Создание локальных пользователей: Справочник по C#

0.00 (0%) 0 votes

ОСТАВЬТЕ ОТВЕТ

Пожалуйста, введите ваш комментарий!
пожалуйста, введите ваше имя здесь