网站首页  词典首页

请输入您要查询的函数:

 

术语 netsessionenum
释义 NetSessionEnum
语法:
C++
NET_API_STATUS NetSessionEnum(
__in LPWSTR servername,
__in LPWSTR UncClientName,
__in LPWSTR username,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__inout LPDWORD resume_handle
);
NetSessionEnum功能
提供有关在服务器建立会话的信息。
参数
服务器名 [in]
指针指向一个字符串,它指定的DNS或NetBIOS的远程服务器上的功能是执行的名称。如果该参数为NULL,则使用本地计算机。
UncClientName [in]
一个字符串指针,指定的计算机会议的信息是要返回的名称。如果该参数为NULL,NetSessionEnum将返回服务器上的所有计算机的会话的信息。
用户名 [in]
一个字符串指针,指定的用户的哪些信息是要返回的名称。如果该参数为NULL,NetSessionEnum返回所有用户的信息。
Level [in]
指定的数据信息的Level。此参数可以是下列值之一。
ValueMeaning
0Return的该届会议上成立了计算机的名称。在bufptr参数指向一个SESSION_INFO_0结构的数组。
1Return计算机的名称,用户名,并打开文件,管道和设备在计算机上。在bufptr参数指向一个SESSION_INFO_1结构的数组。
2英寸除了资料显示为1级,返回客户端类型,以及如何建立用户会话。在bufptr参数指向一个SESSION_INFO_2结构的数组。
10Return计算机的名称,用户名和积极的会议空闲时间。在bufptr参数指向一个SESSION_INFO_10结构的数组。
502Return计算机的名称,用户的名字,打开的文件,管道和设备上的电脑,以及运输的客户端使用的名称。在bufptr参数指向一个SESSION_INFO_502结构的数组。
bufptr [out]
指针的缓冲区,接收数据。这一数据格式取决于Level的参数值。
此缓冲区分配制度,必须使用NetApiBufferFree释放功能。请注意,您必须释放缓冲区,即使函数ERROR_MORE_DATA失败。
prefmaxlen [in]
指定返回数据的首选的最大字节长度。如果您指定MAX_PREFERRED_LENGTH,功能分配用于数据所需的内存量。如果指定这个参数在另一个值,它可以限制的字节数函数返回。如果缓冲区大小不足以容纳所有作品,该函数返回ERROR_MORE_DATA。有关更多信息,请参阅网络管理功能,缓冲器和网络管理功能缓冲区长度。
entriesread [out]
指针的值,它接收元素计数实际列举。
totalentries [out]
指针的值,它接收了本来可以列举参赛总人数从目前的恢复情况。请注意,应用程序应考虑仅作为提示此值。
resume_handle [ in , out ]
指针的值,它包含简历处理,用于现有会话继续搜索。手柄应在第一次调用零,离开后续调用不变。如果resume_handle为NULL,没有恢复处理存储。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值可以是下面的错误代码之一。
返回codeDescription
ERROR_ACCESS_DENIEDThe用户没有获得所需的信息。
ERROR_INVALID_LEVELThe价值Level参数指定无效。
ERROR_INVALID_PARAMETERThe指定的参数无效。
ERROR_MORE_DATAMore项可用。指定一个足够大的缓冲区接收的所有条目。
ERROR_NOT_ENOUGH_MEMORYInsufficient内存可用。
NERR_ClientNameNotFoundA会话不存在与计算机的名称。
NERR_InvalidComputerThe计算机名称是无效的。
NERR_UserNotFoundThe用户名找不到。
备注
管理员或服务器操作员本地组的成员才可以成功地执行第1级或2级的NetSessionEnum功能。没有特殊组成员,是需要0级或10级要求。
如果您是Active Directory的程序,您可以调用某些Active Directory服务接口(ADSI)的方法来达到同样的功能,您可以通过调用实现网络管理会议的功能。有关更多信息,请参阅IADsSession和IADsFileServiceOperations。
实例
下面的代码示例演示如何检索有关使用调用NetSessionEnum功能本届会议的信息。该范例调用NetSessionEnum,指定信息化Level10(SESSION_INFO_10)。通过项目的样品循环和打印检索信息。最后,代码打印的会话总数列举并释放缓冲区的信息分配的内存。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "Netapi32.lib");
#include
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
LPSESSION_INFO_10 pBuf = NULL;
LPSESSION_INFO_10 pTmpBuf;
DWORD dwLevel = 10;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i;
DWORD dwTotalCount = 0;
LPTSTR pszServerName = NULL;
LPTSTR pszClientName = NULL;
LPTSTR pszUserName = NULL;
NET_API_STATUS nStatus;
//
// Check command line arguments.
//
if (argc > 4)
{
wprintf(L"Usage: %s [\\\\\\\\ServerName] [\\\\\\\\ClientName] [UserName]\\n", argv[0]);
exit(1);
}
if (argc >= 2)
pszServerName = argv[1];
if (argc >= 3)
pszClientName = argv[2];
if (argc == 4)
pszUserName = argv[3];
//
// Call the NetSessionEnum function, specifying level 10.
//
do // begin do
{
nStatus = NetSessionEnum(pszServerName,
pszClientName,
pszUserName,
dwLevel,
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = 0; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\\n");
break;
}
//
// Print the retrieved data.
//
wprintf(L"\\n\\tClient: %s\\n", pTmpBuf->sesi10_cname);
wprintf(L"\\tUser: %s\\n", pTmpBuf->sesi10_username);
printf("\\tActive: %d\\n", pTmpBuf->sesi10_time);
printf("\\tIdle: %d\\n", pTmpBuf->sesi10_idle_time);
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
fprintf(stderr, "A system error has occurred: %d\\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
//
// Continue to call NetSessionEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
// Check again for an allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of sessions enumerated.
//
fprintf(stderr, "\\nTotal of %d entries enumerated\\n", dwTotalCount);
return 0;
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderLmshare.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
会话功能
NetSessionGetInfo
SESSION_INFO_0
SESSION_INFO_1
SESSION_INFO_2
SESSION_INFO_10
SESSION_INFO_502
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月30日
==英文原文==NetSessionEnum Function
Provides information about sessions established on a server.
Syntax
C++
NET_API_STATUS NetSessionEnum(
__in LPWSTR servername,
__in LPWSTR UncClientName,
__in LPWSTR username,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__inout LPDWORD resume_handle
);
Parameters
servername [in]
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.
UncClientName [in]
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.
username [in]
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.
level [in]
Specifies the information level of the data. This parameter can be one of the following values.
ValueMeaning
0Return the name of the computer that established the session. The bufptr parameter points to an array of SESSION_INFO_0 structures.
1Return 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.
2In 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.
10Return 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.
502Return 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.

bufptr [out]
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.
prefmaxlen [in]
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 .
entriesread [out]
Pointer to a value that receives the count of elements actually enumerated.
totalentries [out]
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.
resume_handle [in, out]
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.
Return Value
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.
Return codeDescription
ERROR_ACCESS_DENIEDThe user does not have access to the requested information.
ERROR_INVALID_LEVELThe value specified for the level parameter is not valid.
ERROR_INVALID_PARAMETERThe specified parameter is not valid.
ERROR_MORE_DATAMore entries are available. Specify a large enough buffer to receive all entries.
ERROR_NOT_ENOUGH_MEMORYInsufficient memory is available.
NERR_ClientNameNotFoundA session does not exist with the computer name.
NERR_InvalidComputerThe computer name is not valid.
NERR_UserNotFoundThe user name could not be found.

Remarks
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 .
Examples
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");
#include
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
LPSESSION_INFO_10 pBuf = NULL;
LPSESSION_INFO_10 pTmpBuf;
DWORD dwLevel = 10;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i;
DWORD dwTotalCount = 0;
LPTSTR pszServerName = NULL;
LPTSTR pszClientName = NULL;
LPTSTR pszUserName = NULL;
NET_API_STATUS nStatus;
//
// Check command line arguments.
//
if (argc > 4)
{
wprintf(L"Usage: %s [\\\\\\\\ServerName] [\\\\\\\\ClientName] [UserName]\\n", argv[0]);
exit(1);
}
if (argc >= 2)
pszServerName = argv[1];
if (argc >= 3)
pszClientName = argv[2];
if (argc == 4)
pszUserName = argv[3];
//
// Call the NetSessionEnum function, specifying level 10.
//
do // begin do
{
nStatus = NetSessionEnum(pszServerName,
pszClientName,
pszUserName,
dwLevel,
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = 0; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\\n");
break;
}
//
// Print the retrieved data.
//
wprintf(L"\\n\\tClient: %s\\n", pTmpBuf->sesi10_cname);
wprintf(L"\\tUser: %s\\n", pTmpBuf->sesi10_username);
printf("\\tActive: %d\\n", pTmpBuf->sesi10_time);
printf("\\tIdle: %d\\n", pTmpBuf->sesi10_idle_time);
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
fprintf(stderr, "A system error has occurred: %d\\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
//
// Continue to call NetSessionEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do
// Check again for an allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of sessions enumerated.
//
fprintf(stderr, "\\nTotal of %d entries enumerated\\n", dwTotalCount);
return 0;
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderLmshare.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
See Also
Network Management Overview
Network Management Functions
Session Functions
NetSessionGetInfo
SESSION_INFO_0
SESSION_INFO_1
SESSION_INFO_2
SESSION_INFO_10
SESSION_INFO_502
Send comments about this topic to Microsoft
Build date: 7/30/2009
==原始网址==http://msdn.microsoft.com/en-us/library/bb525382(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:17:07