Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement