i have this code to create a local windows user
public 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)
{
LogMessageToFile("error msg" + ex.Message);
return false;
}
}
i tried this on my machine it works fine. but then i put this on windows server. and tried to create a user over there.
First i got the error “General access denied error”
so i made the user an administrator
but now i get the error “The network path was not found”
how can i solve this error.. thanks
I had a very similar issue change the first line to
see if that fixes your issue. And triple check that the program is running with administrator privileges.
The other issue it could be is the server has password complexity requirements and
passwordthat is being passed in to the function does not meet those requirements. Does the problem go away if you pass itASfas123@!fdaas the password?I am 90% sure it is one of those two issues.
For your user groups not saving I am not sure why. Here is a snippit from one of my projects that is doing the same thing you are. I cant see the diffrence.