|
-
August 9th, 2005, 09:28 AM
#1
Current User's NT Login Without NetBios ?
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!
-
August 9th, 2005, 09:35 AM
#2
Re: Current User's NT Login Without NetBios ?
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;
}
-
August 9th, 2005, 10:02 AM
#3
Re: Current User's NT Login Without NetBios ?
Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|