-1

I am trying to validate whether given username/domain name entered by the user is a valid user on the machine, i.e. If a local user account exists for that user on the given machine. (I do not require all Active Directory users. I just want the users who have at least logged into the machine once.)

LogonUser API helps me in validating username/domain name and password combination, but it does not tell me if username/domain name is valid if I do not have access to the password.

Abagga
  • 15
  • 6

1 Answers1

2
BOOL IsValidUser(LPCWSTR username)
{
    LPUSER_INFO_0 info = NULL;

    NET_API_STATUS result = NetUserGetInfo(NULL, username, 0, reinterpret_cast<LPBYTE>(&info));

    NetApiBufferFree(info);

    return result == NERR_Success;
}

Though, note that if this function returns false, it does not mean that the username is invalid. There could be other reasons NetUserGetInfo does not succeed.

(Terribly ugly API.)

Don Reba
  • 13,814
  • 3
  • 48
  • 61
  • Does the API NetUserGetInfo work for domain users on local machine? I see it works for local machine users. For domain users it tries to reach the server. I tried that and it seems it doesn't work for them. Even "Net User"command only lists down local user and not the domain user. – Abagga Sep 22 '15 at 11:52