Получение информации о пользователе.

BOOL GetUserNameAndDomain( HANDLE hUserToken, LPWSTR &wszUserName, LPWSTR &wszUserDomain )
{
	PTOKEN_USER		lpTokenUser;
	SID_NAME_USE		eUse;
	LPWSTR			wszName			= NULL;
	DWORD			dwNameSize		= 0;
	LPWSTR			wszDomain		= NULL;
	DWORD			dwDomainSize	= 0;
	BOOL			bRet			= FALSE;
	if( GetTokenUserInfo( hUserToken,lpTokenUser ) )
	{
		LookupAccountSidW( NULL,lpTokenUser->User.Sid,NULL,&dwNameSize,NULL,&dwDomainSize,&eUse );
		if( dwNameSize > 0 )
		{
			wszName = (LPWSTR)LocalAlloc( LMEM_FIXED | LMEM_ZEROINIT,dwNameSize * sizeof(WCHAR) );
			wszDomain = (LPWSTR)LocalAlloc( LMEM_FIXED | LMEM_ZEROINIT,dwDomainSize * sizeof(WCHAR) );
			if( LookupAccountSidW( NULL,lpTokenUser->User.Sid,wszName,&dwNameSize,wszDomain,
&dwDomainSize,&eUse ) )
			{
				wszUserName = wszName;
				wszUserDomain = wszDomain;
				bRet = TRUE;
			}
			else
			{
				FreeString( wszName );
				FreeString( wszDomain );
			}
		}
		LocalFree( lpTokenUser );
	}
	return bRet;
}