是否有 Windows C++ API 来验证 Windows username/domain 名称是本地计算机上的有效帐户(没有密码)?

Is there a Windows C++ API to validate Windows username/domain name is a valid account on the local machine (without the password)?

我正在尝试验证用户输入的给定 username/domain 名称是否是计算机上的有效用户,即给定计算机上是否存在该用户的本地用户帐户。 (我不需要所有 Active Directory 用户。我只需要至少登录过一次机器的用户。)

LogonUser API 帮助我验证 username/domain 名称和密码组合,但如果我无法访问密码,它不会告诉我 username/domain 名称是否有效。

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;
}

不过,请注意,如果此函数 returns 为 false,并不意味着用户名无效。可能还有其他原因 NetUserGetInfo 没有成功。

(丑得要命API。)