|
|
|
date: Tue, 17 Jun 2008 10:21:05 +0200,
group: microsoft.public.platformsdk.security
back
Re: LsaEnumerateLogonSessions
I've found the solution for my problem.
To determine the current LUID I use the following code:
BOOL GetLUIDOfCurrentUser(void)
{
DWORD dwSize = 0, dwResult = 0;
HANDLE hToken;
PTOKEN_STATISTICS pLUIDInfo;
// Open a handle to the access token for the calling process.
if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ))
{
printf( "OpenProcessToken Error %u\n", GetLastError() );
return FALSE;
}
// Call GetTokenInformation to get the buffer size.
if (!GetTokenInformation(hToken, TokenStatistics, NULL, dwSize,
&dwSize))
{
dwResult = GetLastError();
if( dwResult != ERROR_INSUFFICIENT_BUFFER )
{
printf( "GetTokenInformation Error %u\n", dwResult );
return FALSE;
}
}
// Allocate the buffer.
pLUIDInfo = (PTOKEN_STATISTICS) GlobalAlloc( GPTR, dwSize );
// Call GetTokenInformation again to get the token information (LUID).
if (! GetTokenInformation(hToken, TokenStatistics, pLUIDInfo, dwSize,
&dwSize ) )
{
printf( "GetTokenInformation Error %u\n", GetLastError() );
return FALSE;
}
CString sHelp;
sHelp.Format(TEXT("LUID of current user\n\n")
TEXT("LowPart: %d\n")
TEXT("HighPart: %d\n\n")
TEXT("Value: %I64d"),
pLUIDInfo->AuthenticationId.LowPart, pLUIDInfo->AuthenticationId.HighPart,
pLUIDInfo->AuthenticationId.LowPart +
(__int64)((__int64)pLUIDInfo->AuthenticationId.HighPart << 32));
AfxMessageBox(sHelp);
if ( pLUIDInfo )
{
GlobalFree( pLUIDInfo );
}
return TRUE;
}
Dieter
"Dieter Schmitz" schrieb im Newsbeitrag
news:uuNiXMF0IHA.2312@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I need an unique identifier for all loggon sessions. For that I use
> LsaEnumerateLogonSessions and LsaEnumerateLogonSessions.
>
> I've tried microsofts sample code to enumerate logon sessions which can be
> found under: http://msdn.microsoft.com/en-us/library/aa375400(VS.85).aspx
>
> When I start the program on a terminal server, I see all current sessions
> and some previouly logged off. It seems that windows cleans up this
> structure not directly after a logoff.
>
> I need the LUID of the current session. As the LogonSessions struct could
> hold overaged data, a user with the same sessionID could by found more
> than once.
>
> What is the best way, to find out the current LUID? Ignore overaged data
> and just use the newest entry for duplicate entries?
> Or is there a better way to get the LUID of the current user?
>
> Thanxs
> Dieter
date: Tue, 17 Jun 2008 11:25:52 +0200
author: Dieter Schmitz
|
|