How do you retrieve the NT User's Login Name without resorting to NetUserGetInfo or some other function that requires NetBios to be running ?
Functions that require Active Directory or Net Bios are of no use to me.
Thanks!
Printable View
How do you retrieve the NT User's Login Name without resorting to NetUserGetInfo or some other function that requires NetBios to be running ?
Functions that require Active Directory or Net Bios are of no use to me.
Thanks!
this works in XP, maybe it works in NT too:
Code:CString CMyClass::GetActiveUser()
{
// Declare variables
CString sUsername = "", sDomainName = "", sBuffer, sResult = "";
PSID pSid = NULL;
BYTE bySidBuffer[256];
DWORD dwSidSize = sizeof(bySidBuffer), dwDomainNameSize = 1024, dwUsernameSize = 1024;
SID_NAME_USE sidType;
// Initialize variables
pSid = (PSID)bySidBuffer;
dwSidSize = sizeof(bySidBuffer);
// Get current username
GetUserName(sBuffer.GetBuffer(dwUsernameSize), &dwUsernameSize);
sUsername = sBuffer.GetBuffer(dwUsernameSize);
sBuffer.ReleaseBuffer();
// Get the domain name
LookupAccountName(NULL, sUsername, (PSID) pSid, &dwSidSize,
sBuffer.GetBuffer(dwDomainNameSize), &dwDomainNameSize, (PSID_NAME_USE)&sidType);
sDomainName = sBuffer.GetBuffer(dwDomainNameSize);
sBuffer.ReleaseBuffer();
// Return right result
if (!sDomainName.IsEmpty())
sResult = sDomainName + "\\";
sResult += sUsername;
return sResult;
}
Thank you!
:wave: