CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Location
    Pell City, Alabama
    Posts
    126

    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!

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

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

  3. #3
    Join Date
    May 2004
    Location
    Pell City, Alabama
    Posts
    126

    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
  •  





Click Here to Expand Forum to Full Width

Featured