Provides information about sessions established on a server.
NET_API_STATUS NET_API_FUNCTION NetSessionEnum( LMSTR servername, LMSTR UncClientName, LMSTR username, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle );
Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
Pointer to a string that specifies the name of the computer session for which information is to be returned. If this parameter is NULL, NetSessionEnum returns information for all computer sessions on the server.
Pointer to a string that specifies the name of the user for which information is to be returned. If this parameter is NULL, NetSessionEnum returns information for all users.
Specifies the information level of the data. This parameter can be one of the following values.
||Return the name of the computer that established the session. The bufptr parameter points to an array of SESSION_INFO_0 structures.|
||Return the name of the computer, name of the user, and open files, pipes, and devices on the computer. The bufptr parameter points to an array of SESSION_INFO_1 structures.|
||In addition to the information indicated for level 1, return the type of client and how the user established the session. The bufptr parameter points to an array of SESSION_INFO_2 structures.|
||Return the name of the computer, name of the user, and active and idle times for the session. The bufptr parameter points to an array of SESSION_INFO_10 structures.|
||Return the name of the computer; name of the user; open files, pipes, and devices on the computer; and the name of the transport the client is using. The bufptr parameter points to an array of SESSION_INFO_502 structures.|
Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter.
This buffer is allocated by the system and must be freed using the NetApiBufferFree function. Note that you must free the buffer even if the function fails with ERROR_MORE_DATA.
Specifies the preferred maximum length of returned data, in bytes. If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the data. If you specify another value in this parameter, it can restrict the number of bytes that the function returns. If the buffer size is insufficient to hold all entries, the function returns ERROR_MORE_DATA. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.
Pointer to a value that receives the count of elements actually enumerated.
Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. Note that applications should consider this value only as a hint.
Pointer to a value that contains a resume handle which is used to continue an existing session search. The handle should be zero on the first call and left unchanged for subsequent calls. If resume_handle is NULL, no resume handle is stored.
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
||The user does not have access to the requested information.|
||The value specified for the level parameter is not valid.|
||The specified parameter is not valid.|
||More entries are available. Specify a large enough buffer to receive all entries.|
||Insufficient memory is available.|
||A session does not exist with the computer name.|
||The computer name is not valid.|
||The user name could not be found.|
Only members of the Administrators or Server Operators local group can successfully execute the NetSessionEnum function at level 1 or level 2. No special group membership is required for level 0 or level 10 calls.
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management session functions. For more information, see IADsSession and IADsFileServiceOperations.
The following code sample demonstrates how to retrieve information about current sessions using a call to the NetSessionEnum function. The sample calls NetSessionEnum, specifying information level 10 ( SESSION_INFO_10). The sample loops through the entries and prints the retrieved information. Finally, the code prints the total number of sessions enumerated and frees the memory allocated for the information buffer.
#ifndef UNICODE #define UNICODE #endif #pragma comment(lib, "Netapi32.lib")
|Windows version||Windows XP [desktop apps only] Windows Server 2003 [desktop apps only]|
|Header||lmshare.h (include Lm.h)|