网站首页  词典首页

请输入您要查询的函数:

 

术语 netsessiongetinfo
释义 NetSessionGetInfo
语法:
C++
NET_API_STATUS NetSessionGetInfo(
__in LPWSTR servername,
__in LPWSTR UncClientName,
__in LPWSTR username,
__in DWORD level,
__out LPBYTE *bufptr
);
NetSessionGetInfo功能
信息检索与特定的服务器和工作站建立了会议。
参数
服务器名 [in]
指针指向一个字符串,它指定的DNS或NetBIOS的远程服务器上的功能是执行的名称。如果该参数为NULL,则使用本地计算机。
UncClientName [in]
一个字符串指针,指定的计算机会议的信息是要返回的名称。此参数是必需的,不能为NULL。有关更多信息,请参阅NetSessionEnum。
用户名 [in]
一个字符串指针,指定用户的会话信息的要返回的名称。此参数是必需的,不能为NULL。
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结构。
bufptr [out]
指针的缓冲区,接收数据。这一数据格式取决于Level的参数值。有关更多信息,请参阅网络管理功能,缓冲器和网络管理功能缓冲区长度。
此缓冲区分配制度,必须使用NetApiBufferFree释放功能。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值可以是下面的错误代码之一。
返回codeDescription
ERROR_ACCESS_DENIEDThe用户没有获得所需的信息。
ERROR_INVALID_LEVELThe价值Level参数指定无效。
ERROR_INVALID_PARAMETERThe指定的参数无效。
ERROR_NOT_ENOUGH_MEMORYInsufficient内存可用。
NERR_ClientNameNotFoundA会话不存在与计算机的名称。
NERR_InvalidComputerThe计算机名称是无效的。
NERR_UserNotFoundThe用户名找不到。
备注
管理员或服务器操作员本地组的成员才可以成功地执行第1级或2级的NetSessionGetInfo功能。没有特殊组成员,是需要0级或10级要求。
如果您是Active Directory的程序,您可以调用某些Active Directory服务接口(ADSI)的方法来达到同样的功能,您可以通过调用实现网络管理会议的功能。有关更多信息,请参阅IADsSession和IADsFileServiceOperations。
Server 2003和Windows XP中:如果您拨打信息1级或域控制器上运行Active Directory 2此功能,允许访问或拒绝关于在安全对象的ACL的视窗。要启用匿名访问,用户必须是匿名的Windows 2000以前版本兼容访问组成员。这是因为匿名令牌不包括Everyone组默认的SID。如果您拨打信息1级或成员服务器或工作站,所有的身份验证的用户可以查看信息2此功能。匿名访问也是允许的,如果everyoneincludesanonymous的策略设置允许匿名访问。如需有关限制匿名访问的信息,请参阅的网络管理功能的安全要求。欲了解更多有关的ACL,ACE的,和访问令牌信息,请访问控制模型。
Windows 2000 Server和Windows 2000 Professional的:如果您拨打信息1级或域控制器上运行Active Directory 2此功能,允许访问或拒绝的访问控制列表的安全对象(ACL)的基础。默认的ACL允许所有经过身份验证的用户和Windows 2000以前版本兼容访问组,查看资料。默认情况下,Windows 2000以前版本兼容访问组,包括每个人作为成员。这使得匿名访问的信息如果系统允许匿名访问。有关更多信息,请允许匿名访问。
如果您拨打信息1级或成员服务器或工作站,所有的身份验证的用户可以查看信息2此功能。匿名访问也是允许的,如果RestrictAnonymous的策略设置允许匿名访问。
实例
下面的代码示例演示如何检索有关使用调用NetSessionGetInfo功能会话信息。该范例调用NetSessionGetInfo,指定信息化Level10(SESSION_INFO_10)。如果调用成功,代码打印有关会议的资料。最后,该示例释放的信息缓冲区分配的内存。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "Netapi32.lib");
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 10;
LPSESSION_INFO_10 pBuf = NULL;
LPTSTR pszServerName = NULL;
LPTSTR pszUNCClientName = NULL;
LPTSTR pszUserName = NULL;
NET_API_STATUS nStatus;
//
// Check command line arguments.
//
if (argc == 3)
{
pszUNCClientName = argv[1];
pszUserName = argv[2];
}
else if (argc == 4)
{
pszServerName = argv[1];
pszUNCClientName = argv[2];
pszUserName = argv[3];
}
else
{
wprintf(L"Usage: %s [\\\\\\\\ServerName] \\\\\\\\ClientName UserName\\n", argv[0]);
exit(1);
}
//
// Call the NetSessionGetInfo function, specifying level 10.
//
nStatus = NetSessionGetInfo(pszServerName,
pszUNCClientName,
pszUserName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds,
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
//
// Print the session information.
//
wprintf(L"\\n\\tClient: %s\\n", pBuf->sesi10_cname);
wprintf(L"\\tUser: %s\\n", pBuf->sesi10_username);
printf("\\tActive: %d\\n", pBuf->sesi10_time);
printf("\\tIdle: %d\\n", pBuf->sesi10_idle_time);
}
}
//
// 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);
return 0;
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderLmshare.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
会话功能
NetSessionDel
NetSessionEnum
SESSION_INFO_0
SESSION_INFO_1
SESSION_INFO_2
SESSION_INFO_10
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年7月30日
==英文原文==NetSessionGetInfo Function
Retrieves information about a session established between a particular server and workstation.
Syntax
C++
NET_API_STATUS NetSessionGetInfo(
__in LPWSTR servername,
__in LPWSTR UncClientName,
__in LPWSTR username,
__in DWORD level,
__out LPBYTE *bufptr
);
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. This parameter is required and cannot be NULL. For more information, see NetSessionEnum .
username [in]
Pointer to a string that specifies the name of the user whose session information is to be returned. This parameter is required and cannot be NULL.
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 a SESSION_INFO_0 structure.
1Return the name of the computer, name of the user, and open files, pipes, and devices on the computer. The bufptr parameter points to a SESSION_INFO_1 structure.
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 a SESSION_INFO_2 structure.
10Return the name of the computer; name of the user; and active and idle times for the session. The bufptr parameter points to a SESSION_INFO_10 structure.

bufptr [out]
Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths .
This buffer is allocated by the system and must be freed using the NetApiBufferFree function.
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_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 NetSessionGetInfo 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 .
Windows Server 2003 and Windows XP: If you call this function at information level 1 or 2 on a domain controller that is running Active Directory, access is allowed or denied based on the ACL for the securable object. To enable anonymous access, the user Anonymous must be a member of the Pre-Windows 2000-Compatible Access Group. This is because anonymous tokens do not include the Everyone group SID by default. If you call this function at information level 1 or 2 on a member server or workstation, all authenticated users can view the information. Anonymous access is also permitted if the EveryoneIncludesAnonymous policy setting allows anonymous access. For more information about restricting anonymous access, see Security Requirements for the Network Management Functions . For more information on ACLs, ACEs, and access tokens, see Access Control Model .
Windows 2000 Server and Windows 2000 Professional: If you call this function at information level 1 or 2 on a domain controller that is running Active Directory, access is allowed or denied based on the access control list (ACL) for the securable object. The default ACL permits all authenticated users and members of the Pre-Windows 2000-Compatible Access Group to view the information. By default, the Pre-Windows 2000-Compatible Access Group includes Everyone as a member. This enables anonymous access to the information if the system allows anonymous access. For more information, see Allowing Anonymous Access .
If you call this function at information level 1 or 2 on a member server or workstation, all authenticated users can view the information. Anonymous access is also permitted if the RestrictAnonymous policy setting allows anonymous access.
Examples
The following code sample demonstrates how to retrieve information about a session using a call to the NetSessionGetInfo function. The sample calls NetSessionGetInfo, specifying information level 10 ( SESSION_INFO_10 ). If the call succeeds, the code prints information about the session. Finally, the sample frees the memory allocated for the information buffer.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "Netapi32.lib");
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
DWORD dwLevel = 10;
LPSESSION_INFO_10 pBuf = NULL;
LPTSTR pszServerName = NULL;
LPTSTR pszUNCClientName = NULL;
LPTSTR pszUserName = NULL;
NET_API_STATUS nStatus;
//
// Check command line arguments.
//
if (argc == 3)
{
pszUNCClientName = argv[1];
pszUserName = argv[2];
}
else if (argc == 4)
{
pszServerName = argv[1];
pszUNCClientName = argv[2];
pszUserName = argv[3];
}
else
{
wprintf(L"Usage: %s [\\\\\\\\ServerName] \\\\\\\\ClientName UserName\\n", argv[0]);
exit(1);
}
//
// Call the NetSessionGetInfo function, specifying level 10.
//
nStatus = NetSessionGetInfo(pszServerName,
pszUNCClientName,
pszUserName,
dwLevel,
(LPBYTE *)&pBuf);
//
// If the call succeeds,
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
//
// Print the session information.
//
wprintf(L"\\n\\tClient: %s\\n", pBuf->sesi10_cname);
wprintf(L"\\tUser: %s\\n", pBuf->sesi10_username);
printf("\\tActive: %d\\n", pBuf->sesi10_time);
printf("\\tIdle: %d\\n", pBuf->sesi10_idle_time);
}
}
//
// 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);
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
NetSessionDel
NetSessionEnum
SESSION_INFO_0
SESSION_INFO_1
SESSION_INFO_2
SESSION_INFO_10
Send comments about this topic to Microsoft
Build date: 7/30/2009
==原始网址==http://msdn.microsoft.com/en-us/library/bb525383(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:25:37