Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
User Action:

Enumerating Logon Sessions

The following example calls the LsaEnumerateLogonSessions function to retrieve a list of logon session identifiers and the number of sessions on the system.

In the following example, the GetSessionData function takes a pointer to a valid LUID logon session identifier and displays detailed information about the session. This function is used for purposes of illustration only; GetSessionData is neither part of, nor required by, the Local Security Authority (LSA). For the implementation of this example function, see Retrieving Logon Session Information.

Note  The LsaNtStatusToWinError function converts an NTSTATUS code to a Windows error code.
// Copyright (c) Microsoft Corporation. All rights reserved.
#include <windows.h>
#include <stdio.h>

// The following constant may be defined by including NtStatus.h.
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)

// The LSA authentication functions are available in Unicode only.
#define UNICODE

int _cdecl main()
{
  PLUID sessions;
  ULONG count;
  NTSTATUS retval;
  int i;

  retval = LsaEnumerateLogonSessions(&count, &sessions);

  if (retval != STATUS_SUCCESS) {
     wprintf (L"LsaEnumerate failed %lu\n",
       LsaNtStatusToWinError(retval));
    return 1;
  } 
  wprintf (L"Enumerate sessions received %lu sessions.\n", count);

  // Process the array of session LUIDs...
  for (i =0;i < (int) count; i++) {
    GetSessionData (&sessions[i]);
  }

  // Free the array of session LUIDs allocated by the LSA.
  LsaFreeReturnBuffer(sessions);
  return 0;
}

 

 

Send comments about this topic to Microsoft

Build date: 4/6/2010