When my software is run my software most be get type of login of the windows user. Login by domain or local. I need to get type of login of the user in windows.
I think these APIs can help me:
GetComputerNameEx( ComputerNameDnsDomain, domainNameBuf, &bufSize );
or
GetUserName(sBuffer.GetBuffer(dwUsernameSize), &dwUsernameSize);
or
LookupAccountName(NULL,
sUsername,
(PSID)pSid,
&dwSidSize,
sBuffer.GetBuffer(dwDomainNameSize),
&dwDomainNameSize,
(PSID_NAME_USE)&sidType);
or
nStatus = NetWkstaUserGetInfo(NULL,dwLevel,(LPBYTE *)&pBuf);
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 and you can assume the user is logged into a local account.
Otherwise, use GetTokenInformation
with TokenUser
to retrieve the SID for the current user, 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.
You can do it in a simple way, why don't you just use GetEnvironmentVariable to retreive USERDOMAIN
and then compare with COMPUTERNAME
. If they are identical then the user is logged localy, in the other way the user is logged using the domain.
you also got the command line WHOAMI.EXE
that gives you the information and the one I use is retreiving the WMI object win32_computersystem
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With