1

I have created a local user. (Ex: mymachine\user1). I do not want to add this user to administrator group.

I have used following c# code to validate my local account:

PrincipalContext contextmachine = new PrincipalContext(ContextType.Machine);    
valid = contextmachine.ValidateCredentials(accountname, password);

But it is giving exception as:

Logon failure: the user has not been granted the requested logon type at this computer.

please help me if I m doing it in a right way.

1 Answers1

0

Try this:

PrincipalContext contextmachine = new PrincipalContext(ContextType.Machine);
valid = contextmachine.ValidateCredentials(accountname, password);

UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, userId);  
foreach (Principal p in usr.GetAuthorizationGroups())
{
    if (p.ToString() == "Administrators")
    {
        result = true;
    }
}
jomsk1e
  • 3,585
  • 7
  • 34
  • 59