-
Notifications
You must be signed in to change notification settings - Fork 3
User
This package provides functionality for managing local user's accounts and user's local groups in basic scenarios.
Before you start see main prerequisites.
var factory = new ContinuousManagementFactory();
var _userShell = factory.UserShell();
var _groupShell = factory.LocalUserGroup();Add new user:
// in package older than 1.2.1 use UserModel class
var user = new LocalUserCreateModel
{
Name = "testUser1",
FullName = "Test User 1",
Description = "Delete this user after tests",
Password = "Test123",
Expires = new DateTime(2018, 01, 01)
};
_userShell.Create(user);Leave Expires = null if user account should never expire.
If you try add user with already existing name, the MethodInvocationException will occur.
Remove existing user:
_userShell.Remove(userName);if you try remove non-existing user the MethodInvocationException will occur.
Remove existing user with windows user profile:
_userShell.Remove(userName, true);if you try remove non-existing user the MethodInvocationException will occur.
Remove existing user:
var user = new LocalUserInfo("userName");
user.Remove();if you try to create user instance for non-existing user or remove already removed user the MethodInvocationException will occur.
Remove existing user with windows user profile:
user.RemoveWithProfile();if you try to create user instance for non-existing user or remove already removed user the MethodInvocationException will occur.
Get existing user:
// in package older than v1.2.1 use _userShell.Get(userName);
LocalUserInfo user = _userShell.GetLocalUser(userName);Returns null if user is not existing.
Get existing user:
var user = new LocalUserInfo("userName");Throws MethodInvocationException if user doesn't exists.
Refresh properties in current user instance:
var user = new LocalUserInfo("userName");
user.Refresh();Throws MethodInvocationException if user doesn't exists.
Get user which is currently logged in:
LocalUserInfo user = _userShell.GetLoggedInUser();Get all users from current domain:
List<LocalUserInfo> users = _userShell.GetAllUsers();Check if user exists
bool exists = _userShell.Exists(userName);Returns true if user exists.
Check if user exists
var user = new LocalUserInfo("userName"); // throws exception when user doesn't exist
bool exists = user.Exists(); // if user has been removed, returns falseReturns true if user still existing.
Change existing user password:
// not secure
_userShell.ChangePassword("userName", "newPassword");
// secure
var securePassword = new SecurePassword();
securePassword.AppendChar('n');
securePassword.AppendChar('W');
securePassword.AppendChar('x');
_shell.ChangePassword("userName", securePassword);If you try change password in non-existing user the MethodInvocationException will occur.
Change password in current user:
var securePassword = new SecurePassword();
securePassword.AppendChar('n');
securePassword.AppendChar('W');
securePassword.AppendChar('x');
var user = new LocalUserInfo("userName");
user.Change()
.Password(securePassword)
.Apply();If you try change password in non-existing user the MethodInvocationException will occur.
Specify whether the password will required at user logon:
_userShell.SetPasswordRequired(userName, false);User as default has set this value to true.
If user is not existing, the MethodInvocationException will occur.
Specify whether the password will required at user logon:
var user = new LocalUserInfo("userName");
user.Change()
.PasswordRequired(false)
.Apply();If user is not existing, the MethodInvocationException will occur.
Specify whether user be able to change his password:
_userShell.SetPasswordCanBeChangedByUser(userName, false);User as default has set this value to true.
If user is not existing, the MethodInvocationException will occur.
Specify wheter the password can be changed by user:
var user = new LocalUserInfo("userName");
user.Change()
.PasswordCanBeChangedByUser(false)
.Apply();If user is not existing, the MethodInvocationException will occur.
Specify whether the user's password can expire:
_userShell.SetPasswordCanExpire(userName, false);User as default has set this value to true.
If user is not existing, the MethodInvocationException will occur.
Specify wheter the password can expire:
var user = new LocalUserInfo("userName");
user.Change()
.PasswordCanExpire(true)
.Apply();If user is not existing, the MethodInvocationException will occur.
Specify whether the user's password is expired:
_userShell.SetPasswordExpired(userName, true);If true, user will be forced to change the password at next login.
If user is not existing, the MethodInvocationException will occur.
Specify whether the user's password is expired:
var user = new LocalUserInfo("userName");
user.Change()
.PasswordExpired(true)
.Apply();If true, user will be forced to change the password at next login.
If user is not existing, the MethodInvocationException will occur.
Specify whether the user's account is disabled:
_userShell.SetAccountDisabled(userName, true);If true, the account will be disabled and user will not be able to login.
If user is not existing, the MethodInvocationException will occur.
Specify whether the user's account is disabled:
var user = new LocalUserInfo("userName");
user.Change()
.AccountDisabled(true)
.Apply();If true, the account will be disabled and user will not be able to login.
If user is not existing, the MethodInvocationException will occur.
Set user visibility in windows welcome (login) screen:
_userShell.SetUserVisibility(userName, false); //hide userIf false, user will be hidden in windows welcome screen. As default, visibility is always set to true.
If user is not existing, the MethodInvocationException will occur.
Set user visibility in windows welcome (login) screen: Specify whether the user's account is disabled:
var user = new LocalUserInfo("userName");
user.Change()
.IsVisible(false)
.Apply();If false, user will be hidden in windows welcome screen. As default, visibility is always set to true.
If user is not existing, the MethodInvocationException will occur.
Set user description:
_userShell.SetUserDescription(userName, "description"); If user is not existing, the MethodInvocationException will occur.
Set user description:
var user = new LocalUserInfo("userName");
user.Change()
.Description("description")
.Apply();If user is not existing, the MethodInvocationException will occur.
Set user full name:
_userShell.SetUserFullName("userName", "user full name");If user is not existing, the MethodInvocationException will occur.
Change user full name:
var user = new LocalUserInfo("userName");
user.Change()
.FullName("new full name")
.Apply();If user is not existing, the MethodInvocationException will occur.
Create new local group:
_groupShell.Create(groupName, groupDescription);If you try add group with already existing name, the MethodInvocationException will occur.
Remove existing group:
_groupShell.Remove(groupName);If you try remove non-existing group, the MethodInvocationException will occur.
Get existing group:
var group = _groupShell.Get("groupName");With this method you can get group group.Name, group.Description and all user names who are assigned to this group as group.Members.
Return null if group not exists.
Get existing group by SID property:
var group = _groupShell.GetBySid("sid");With this method you can get group group.Name, group.Description and all user names who are assigned to this group as group.Members.
Return null if group not exists.
assign list of users to existing group:
var groupName = "testGroup";
var users = new List<string> { "User1" };
_groupShell.AssignUsers(groupName, users);If you try assign empty or null list of users or provide invalid groupName, the MethodInvocationException will occur.
assign single user to existing group:
var groupName = "testGroup";
var user = "User1";
_groupShell.AssignUser(groupName, user);If you try assign not existing user or provide invalid groupName, the MethodInvocationException will occur.
remove assigned users from existing group:
var groupName = "testGroup";
var users = new List<string> { "User1" };
_groupShell.RemoveUsers(groupName, users);If you try remove empty or null user's list or provide invalid groupName, the MethodInvocationException will occur.
remove assigned user from existing group:
var groupName = "testGroup";
var user = "User1";
_groupShell.RemoveUser(groupName, user);If you try remove not exiting user or provide invalid groupName, the MethodInvocationException will occur.
Get all user names assigned to specific group:
var groupName = "testGroup";
List<string> userNames;
userNames = _groupShell.GetMembers(groupName);If you provide invalid groupName, the MethodInvocationException will occur.