IHSMQ
IHSMQ

Reputation: 13

LookupAccountName to get user account type VC++

I need to check whether a provided user name is a local or domain user in VC++. I thought LookupAccountName was going to give me what I needed because of the last argument. I used it to get the SID from an account name, it works perfectly fine and gives me the correct SID, but not he correct SID_NAME_USE. The website says:

peUse [out]: A pointer to a SID_NAME_USE enumerated type that indicates the type of the account when the function returns.

However peUse is always SidTypeUser no matter what type of user I supply (local user or domain user). I also tried with LookupAccountSid and I'm getting the same thing. Here are my questions then:

  1. Can I use LookUpAccountName or LookupAccountSid to get the correct account type?
  2. Why is the function always returning SidTypeUser as the user type?
  3. Is there any other way to check whether a user is domain or local user from its SID or username?

Please someone help me, I have stuck on this for a while now.

Thanks!

Upvotes: 1

Views: 1890

Answers (1)

Harry Johnston
Harry Johnston

Reputation: 36328

Use LsaQueryInformationPolicy with PolicyDnsDomainInformation to retrieve the SID for the computer's primary domain. (If the Sid member is NULL, the computer is not joined to a domain.)

Otherwise, use LookupAccountName to retrieve the SID you are interested in, then use GetWindowsAccountDomainSid to extract the domain part of the user's SID.

Compare the primary domain's SID to the user's domain SID using EqualSid. If the SIDs are equal, the user is logged into a domain account; otherwise, the user is logged into a local account.

Upvotes: 1

Related Questions