网站首页  词典首页

请输入您要查询的函数:

 

术语 netserverenum
释义 NetServerEnum
语法:
C++
NET_API_STATUS NetServerEnum(
__in_opt LPCWSTR servername,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__in DWORD servertype,
__in_opt LPCWSTR domain,
__inout_opt LPDWORD resume_handle
);
的NetServerEnum功能
该函数的NetServerEnum列出指定类型的域在可见的所有服务器。例如,一个应用程序可以调用的NetServerEnum列出所有域控制器的唯一或所有SQL服务器只。
您可以结合位掩码列出几种类型。例如,联合收割机的0x00000003值为SV_TYPE_WORKSTATION(0x00000001)和SV_TYPE_SERVER(00000000)的位掩码。
如果您需要更多的特定服务器的信息,调用WNetEnumResource函数。
参数
服务器名[中,可选]
版权所有;必须为NULL。
Level [in]
数据的信息化Level的要求。此参数可以是下列值之一。
ValueMeaning
100Return服务器名称和平台信息。在bufptr参数指向一个SERVER_INFO_100结构的数组。
101Return服务器名称,类型和相关软件。在bufptr参数指向一个SERVER_INFO_101结构的数组。
bufptr [out]
一个缓冲区,接收数据的指针。这一数据格式取决于Level的参数值。此缓冲区分配制度,必须使用NetApiBufferFree释放功能。请注意,您必须释放缓冲区,即使函数ERROR_MORE_DATA失败。
prefmaxlen [in]
返回的数据的更好的最大长度,以字节为单位。如果您指定MAX_PREFERRED_LENGTH,功能分配用于数据所需的内存量。如果指定这个参数在另一个值,它可以限制的字节数函数返回。如果缓冲区大小不足以容纳所有作品,该函数返回ERROR_MORE_DATA。有关更多信息,请参阅网络管理功能,缓冲器和网络管理功能缓冲区长度。
entriesread [out]
一个值,接收元素计数实际列举的指针。
totalentries [out]
一个值,可见接收服务器和工作站网络上的总人数的指针。请注意,应用程序应考虑仅作为提示此值。
servertype [in]
过滤器的值项的服务器返回的枚举。此参数可以是一个或多个下列值。
ValueMeaning
SV_TYPE_WORKSTATIONAll工作站。
SV_TYPE_SERVERAll计算机上运行服务器服务。
SV_TYPE_SQLSERVERAny服务器运行Microsoft SQL Server。
SV_TYPE_DOMAIN_CTRLA服务器,主域控制器。
SV_TYPE_DOMAIN_BAKCTRLAny服务器是备份域控制器。
SV_TYPE_TIME_SOURCEAny服务器运行262680服务。
SV_TYPE_AFPAny服务器运行苹果的文件协议(AFP),文件服务。
SV_TYPE_NOVELLAny服务器是Novell服务器。
SV_TYPE_DOMAIN_MEMBERAny计算机网络管理2.X的域的成员。
SV_TYPE_LOCAL_LIST_ONLYAny计算机保持在由浏览器的列表。请参见下面的备注部分。
SV_TYPE_PRINTQ_SERVERAny计算机共享打印队列。
SV_TYPE_DIALIN_SERVERAny服务器在运行拨号服务。
SV_TYPE_XENIX_SERVERAny服务器是服务器的XENIX。
SV_TYPE_SERVER_MFPNAny服务器运行为NetWare服务的Microsoft文件和打印。
SV_TYPE_NTA工作站或服务器。
SV_TYPE_WFWAny计算机上运行Windows for Workgroups的。
SV_TYPE_SERVER_NTAny服务器不是域控制器。
SV_TYPE_POTENTIAL_BROWSERAny电脑,可以运行浏览器服务。
SV_TYPE_BACKUP_BROWSERA计算机上运行的备份浏览器的服务。
SV_TYPE_MASTER_BROWSERA计算机运行主浏览器服务。
SV_TYPE_DOMAIN_MASTERA计算机上运行域主浏览器。
SV_TYPE_DOMAIN_ENUMThe主域。
SV_TYPE_WINDOWSA计算机上运行Windows。
SV_TYPE_ALLAll服务器。
SV_TYPE_TERMINALSERVERA服务器运行终端服务器服务。
SV_TYPE_CLUSTER_NTServer集群域中可用。
SV_TYPE_CLUSTER_VS_NTCluster域中的虚拟服务器。
Windows 2000中:此值不支持。
域[中,可选]
一个字符串常量,指定的域的服务器列表将返回名称的指针。该域名必须是一个NetBIOS(例如域名,微软)。是的NetServerEnum函数不支持DNS风格的名字(例如,microsoft.com)。
如果该参数为NULL,则主域是不言而喻的。
resume_handle [中,指出,可选]
版权所有;必须设置为零。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值可以是下面的错误代码之一:
返回代码/ valueDescription
ERROR_ACCESS_DENIED
5Access被拒绝。
ERROR_INVALID_PARAMETER
87The参数不正确。
ERROR_MORE_DATA
234More项可用。指定一个足够大的缓冲区接收的所有条目。
ERROR_NO_BROWSER_SERVERS_FOUND
6118No浏览器的服务器上。
ERROR_NOT_SUPPORTED
50The不支持请求。
NERR_ServerNotStarted
2114The服务器服务未启动。
NERR_ServiceNotInstalled
2184The服务尚未启动。
NERR_WkstaNotStarted
2138The工作站服务尚未启动。本地工作站的服务将被用于通信与下级远程服务器。
备注
没有特殊组成员必须成功执行的NetServerEnum功能。
如果指定值SV_TYPE_LOCAL_LIST_ONLY的的NetServerEnum函数返回服务器的浏览器维护内部清单。这意味着仅在主浏览器(或在已过去主浏览器的计算机)。主浏览器是目前电脑的权利,以确定哪些计算机可以服务器或网络上的工作站。
如果没有找到符合的服务器在servertype参数中指定的类型,的NetServerEnum函数返回NULL和DWORD值bufptr参数所指向的entriesread和totalentries参数设置为零。
在功能上的NetServerEnum浏览器服务依赖正在安装和运行。如果没有找到服务器浏览器,然后的NetServerEnum失败,ERROR_NO_BROWSER_SERVERS_FOUND。
如果您是Active Directory的程序,您可以调用某些Active Directory服务接口(ADSI)的方法来达到同样的功能,可以实现通过调用网络管理服务器功能。有关更多信息,请参阅IADsComputer。
实例
下面的代码示例演示了如何列出所有服务器都在一个域可见,以对的NetServerEnum函数调用。该范例调用的NetServerEnum,指定信息化Level101(SERVER_INFO_101)。如果发现任何服务器,通过作品示例代码循环和打印检索到的数据。如果服务器是域控制器,它标识为无论是主域控制器(PDC)或备份域控制器(BDC)服务器。该示例还打印的作品总数量和对实际列举数项提示,警告用户,如果所有项目都没有列举。最后,该示例释放的信息缓冲区分配的内存。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
#include
int wmain(int argc, wchar_t * argv[])
{
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_SERVER; // all servers
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
LPWSTR pszDomainName = NULL;
DWORD i;
if (argc > 2)
 {
fwprintf(stderr, L"Usage: %s [DomainName]\\n", argv[0]);
exit(1);
}
// The request is not for the primary domain.
//
if (argc == 2)
pszDomainName = argv[1];
//
// Call the NetServerEnum function to retrieve information
// for all servers, specifying information level 101.
//
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) & pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
pszDomainName,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
if ((pTmpBuf = pBuf) != NULL) {
//
// Loop through the entries and
// print the data for all server types.
//
for (i = 0; i < dwEntriesRead; i++) {
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL) {
fprintf(stderr, "An access violation has occurred\\n");
break;
}
printf("\\tPlatform: %d\\n", pTmpBuf->sv101_platform_id);
wprintf(L"\\tName: %s\\n", pTmpBuf->sv101_name);
printf("\\tVersion: %d.%d\\n",
pTmpBuf->sv101_version_major,
pTmpBuf->sv101_version_minor);
printf("\\tType: %d", pTmpBuf->sv101_type);
//
// Check to see if the server is a domain controller;
// if so, identify it as a PDC or a BDC.
//
if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_CTRL)
wprintf(L" (PDC)");
else if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
wprintf(L" (BDC)");
printf("\\n");
//
// Also print the comment associated with the server.
//
wprintf(L"\\tComment: %s\\n\\n", pTmpBuf->sv101_comment);
pTmpBuf++;
dwTotalCount++;
}
// Display a warning if all available entries were
// not enumerated, print the number actually
// enumerated, and the total number available.
if (nStatus == ERROR_MORE_DATA) {
fprintf(stderr, "\\nMore entries available!!!\\n");
fprintf(stderr, "Total entries: %d", dwTotalEntries);
}
printf("\\nEntries enumerated: %d\\n", dwTotalCount);
} else {
printf("No servers were found\\n");
printf("The buffer (bufptr) returned was NULL\\n");
printf(" entriesread: %d\\n", dwEntriesRead);
printf(" totalentries: %d\\n", dwEntriesRead);
}
} else
fprintf(stderr, "NetServerEnum failed with error: %d\\n", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}

要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderLmserver.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
服务器功能
NetServerDiskEnum
NetQueryDisplayInformation
SERVER_INFO_100
SERVER_INFO_101
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月13日
==英文原文==NetServerEnum Function
The NetServerEnum function lists all servers of the specified type that are visible in a domain. For example, an application can call NetServerEnum to list all domain controllers only or all SQL servers only.
You can combine bit masks to list several types. For example, a value of 0x00000003 combines the bit masks for SV_TYPE_WORKSTATION (0x00000001) and SV_TYPE_SERVER (0x00000002).
If you require more information for a specific server, call the WNetEnumResource function.
Syntax
C++
NET_API_STATUS NetServerEnum(
__in_opt LPCWSTR servername,
__in DWORD level,
__out LPBYTE *bufptr,
__in DWORD prefmaxlen,
__out LPDWORD entriesread,
__out LPDWORD totalentries,
__in DWORD servertype,
__in_opt LPCWSTR domain,
__inout_opt LPDWORD resume_handle
);
Parameters
servername [in, optional]
Reserved; must be NULL.
level [in]
The information level of the data requested. This parameter can be one of the following values.
ValueMeaning
100Return server names and platform information. The bufptr parameter points to an array of SERVER_INFO_100 structures.
101Return server names, types, and associated software. The bufptr parameter points to an array of SERVER_INFO_101 structures.

bufptr [out]
A 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]
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]
A pointer to a value that receives the count of elements actually enumerated.
totalentries [out]
A pointer to a value that receives the total number of visible servers and workstations on the network. Note that applications should consider this value only as a hint.
servertype [in]
A value that filters the server entries to return from the enumeration. This parameter can be one or more of the following values.
ValueMeaning
SV_TYPE_WORKSTATIONAll workstations.
SV_TYPE_SERVERAll computers that run the Server service.
SV_TYPE_SQLSERVERAny server that runs Microsoft SQL Server.
SV_TYPE_DOMAIN_CTRLA server that is primary domain controller.
SV_TYPE_DOMAIN_BAKCTRLAny server that is a backup domain controller.
SV_TYPE_TIME_SOURCEAny server that runs the Timesource service.
SV_TYPE_AFPAny server that runs the Apple Filing Protocol (AFP) file service.
SV_TYPE_NOVELLAny server that is a Novell server.
SV_TYPE_DOMAIN_MEMBERAny computer that is LAN Manager 2.x domain member.
SV_TYPE_LOCAL_LIST_ONLYAny computer maintained in a list by the browser. See the following Remarks section.
SV_TYPE_PRINTQ_SERVERAny computer that shares a print queue.
SV_TYPE_DIALIN_SERVERAny server that runs a dial-in service.
SV_TYPE_XENIX_SERVERAny server that is a Xenix server.
SV_TYPE_SERVER_MFPNAny server that runs the Microsoft File and Print for NetWare service.
SV_TYPE_NTA workstation or server.
SV_TYPE_WFWAny computer that runs Windows for Workgroups.
SV_TYPE_SERVER_NTAny server that is not a domain controller.
SV_TYPE_POTENTIAL_BROWSERAny computer that can run the browser service.
SV_TYPE_BACKUP_BROWSERA computer that runs a browser service as backup.
SV_TYPE_MASTER_BROWSERA computer that runs the master browser service.
SV_TYPE_DOMAIN_MASTERA computer that runs the domain master browser.
SV_TYPE_DOMAIN_ENUMThe primary domain.
SV_TYPE_WINDOWSA computer that runs Windows.
SV_TYPE_ALLAll servers.
SV_TYPE_TERMINALSERVERA server running the Terminal Server service.
SV_TYPE_CLUSTER_NTServer clusters available in the domain.
SV_TYPE_CLUSTER_VS_NTCluster virtual servers available in the domain.
Windows 2000: This value is not supported.

domain [in, optional]
A pointer to a constant string that specifies the name of the domain for which a list of servers is to be returned. The domain name must be a NetBIOS domain name (for example, microsoft). The NetServerEnum function does not support DNS-style names (for example, microsoft.com).
If this parameter is NULL, the primary domain is implied.
resume_handle [in, out, optional]
Reserved; must be set to zero.
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 code/valueDescription
ERROR_ACCESS_DENIED
5Access was denied.
ERROR_INVALID_PARAMETER
87The parameter is incorrect.
ERROR_MORE_DATA
234More entries are available. Specify a large enough buffer to receive all entries.
ERROR_NO_BROWSER_SERVERS_FOUND
6118No browser servers found.
ERROR_NOT_SUPPORTED
50The request is not supported.
NERR_ServerNotStarted
2114The server service is not started.
NERR_ServiceNotInstalled
2184The service has not been started.
NERR_WkstaNotStarted
2138The Workstation service has not been started. The local workstation service is used to communicate with a downlevel remote server.

Remarks
No special group membership is required to successfully execute the NetServerEnum function.
If you specify the value SV_TYPE_LOCAL_LIST_ONLY, the NetServerEnum function returns the list of servers that the browser maintains internally. This has meaning only on the master browser (or on a computer that has been the master browser in the past). The master browser is the computer that currently has rights to determine which computers can be servers or workstations on the network.
If there are no servers found that match the types specified in the servertype parameter, the NetServerEnum function returns the bufptr parameter as NULL and DWORD values pointed to by the entriesread and totalentries parameters are set to zero.
The NetServerEnum function depends on the browser service being installed and running. If no browser servers are found, then NetServerEnum fails with ERROR_NO_BROWSER_SERVERS_FOUND.
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same function you can achieve by calling the network management server functions. For more information, see IADsComputer .
Examples
The following code sample demonstrates how to list all servers that are visible in a domain with a call to the NetServerEnum function. The sample calls NetServerEnum, specifying information level 101 ( SERVER_INFO_101 ). If any servers are found, the sample code loops through the entries and prints the retrieved data. If the server is a domain controller, it identifies the server as either a primary domain controller (PDC) or a backup domain controller (BDC). The sample also prints the total number of entries available and a hint about the number of entries actually enumerated, warning the user if all entries were not enumerated. Finally, the sample 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[])
{
LPSERVER_INFO_101 pBuf = NULL;
LPSERVER_INFO_101 pTmpBuf;
DWORD dwLevel = 101;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwTotalCount = 0;
DWORD dwServerType = SV_TYPE_SERVER; // all servers
DWORD dwResumeHandle = 0;
NET_API_STATUS nStatus;
LPWSTR pszServerName = NULL;
LPWSTR pszDomainName = NULL;
DWORD i;
if (argc > 2)
 {
fwprintf(stderr, L"Usage: %s [DomainName]\\n", argv[0]);
exit(1);
}
// The request is not for the primary domain.
//
if (argc == 2)
pszDomainName = argv[1];
//
// Call the NetServerEnum function to retrieve information
// for all servers, specifying information level 101.
//
nStatus = NetServerEnum(pszServerName,
dwLevel,
(LPBYTE *) & pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
dwServerType,
pszDomainName,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA)) {
if ((pTmpBuf = pBuf) != NULL) {
//
// Loop through the entries and
// print the data for all server types.
//
for (i = 0; i < dwEntriesRead; i++) {
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL) {
fprintf(stderr, "An access violation has occurred\\n");
break;
}
printf("\\tPlatform: %d\\n", pTmpBuf->sv101_platform_id);
wprintf(L"\\tName: %s\\n", pTmpBuf->sv101_name);
printf("\\tVersion: %d.%d\\n",
pTmpBuf->sv101_version_major,
pTmpBuf->sv101_version_minor);
printf("\\tType: %d", pTmpBuf->sv101_type);
//
// Check to see if the server is a domain controller;
// if so, identify it as a PDC or a BDC.
//
if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_CTRL)
wprintf(L" (PDC)");
else if (pTmpBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
wprintf(L" (BDC)");
printf("\\n");
//
// Also print the comment associated with the server.
//
wprintf(L"\\tComment: %s\\n\\n", pTmpBuf->sv101_comment);
pTmpBuf++;
dwTotalCount++;
}
// Display a warning if all available entries were
// not enumerated, print the number actually
// enumerated, and the total number available.
if (nStatus == ERROR_MORE_DATA) {
fprintf(stderr, "\\nMore entries available!!!\\n");
fprintf(stderr, "Total entries: %d", dwTotalEntries);
}
printf("\\nEntries enumerated: %d\\n", dwTotalCount);
} else {
printf("No servers were found\\n");
printf("The buffer (bufptr) returned was NULL\\n");
printf(" entriesread: %d\\n", dwEntriesRead);
printf(" totalentries: %d\\n", dwEntriesRead);
}
} else
fprintf(stderr, "NetServerEnum failed with error: %d\\n", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}

Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderLmserver.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
See Also
Network Management Overview
Network Management Functions
Server Functions
NetServerDiskEnum
NetQueryDisplayInformation
SERVER_INFO_100
SERVER_INFO_101
Send comments about this topic to Microsoft
Build date: 8/13/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa370623(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 11:31:15