Platform SDK: Network Management |
The NetConnectionEnum function lists all connections made to a shared resource on the server or all connections established from a particular computer. If there is more than one user using this connection, then it is possible to get more than one structure for the same connection, but with a different user name.
Admin or server, print, or comm operator group membership is required to successfully execute the NetConnectionEnum function.
Windows NT/2000: The parameter order is as follows.
NET_API_STATUS NetConnectionEnum( LPWSTR servername, LPWSTR qualifier, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle );
Windows 95/98: The calling application must use the cbBuffer parameter to specify the size, in bytes, of the information buffer pointed to by the pbBuffer parameter. (The cbBuffer parameter replaces the Windows NT/Windows 2000 prefmaxlen parameter.) A resume handle parameter is not available on this platform. Therefore, the parameter list is as follows.
extern API_FUNCTION NetConnectionEnum( const char FAR *pszServer, const char FAR *pszQualifier, short sLevel, char FAR *pbBuffer, unsigned short cbBuffer, unsigned short FAR *pcEntriesRead, unsigned short FAR *pcTotalAvail );
Value | Meaning |
---|---|
0 | Return connection identifiers.
Windows NT/2000: The bufptr parameter is a pointer to an array of CONNECTION_INFO_0 structures. |
1 | Return connection identifiers and connection information.
Windows NT/2000: The bufptr parameter is a pointer to an array of CONNECTION_INFO_1 structures. Windows 95/98: The pbBuffer parameter is a pointer to an array of connection_info_1 structures. |
50 | Return connection information.
Windows 95/98: The pbBuffer parameter is a pointer to an array of connection_info_50 structures. |
Windows NT/2000: 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.
Windows 95/98: The caller must allocate and deallocate this buffer.
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value is a Win32 API error code. For a list of error codes, see Error Codes.
Windows 95/98: See the NetConnectionEnum Sample (Windows 95/98) topic to view a code sample that demonstrates how to use the NetConnectionEnum function.
Windows NT/2000: The following code sample demonstrates how to list the connections made to a shared resource with a call to the NetConnectionEnum function. The sample calls NetConnectionEnum, specifying information level 1 (CONNECTION_INFO_1). If there are entries to return, it prints the values of the coni1_username and coni1_netname members. If there are no entries to return, the sample prints an appropriate message. Finally, the code sample frees the memory allocated for the information buffer.
#define UNICODE #include <windows.h> #include <lm.h> #include <stdio.h> void wmain(int argc, wchar_t *argv[ ]) { DWORD res, i, er = 0, tr = 0, resume = 0; PCONNECTION_INFO_1 p,b; LPTSTR lpszServer = NULL, lpszShare = NULL; if(argc<2) wprintf(L"Syntax: %s [ServerName] ShareName | \\\\ComputerName\n", argv[0]); else { // // The server is not the default local computer. // if(argc>2) lpszServer=argv[1]; // // ShareName is always the last argument. // lpszShare=argv[argc - 1]; // // Call the NetConnectionEnum function, // specifying information level 1. // res=NetConnectionEnum(lpszServer, lpszShare, 1, (LPBYTE *) &p, -1, &er, &tr, &resume); // // If no error occurred, // if(res == 0) { // // If there were any results, // if(er>0) { b=p; // // Loop through the entries; print username and netname. // for(i=0;i<er;i++) { printf("%S\t%S\n", b->coni1_username,b->coni1_netname); b++; } // Free the allocated buffer. // NetApiBufferFree(p); } // Otherwise, print a message depending on whether // the qualifier parameter was a computer (\\ComputerName) // or a share (ShareName). // else { if(lpszShare[0]=='\\') printf("No connection to %S from %S\n", (lpszServer == NULL)?TEXT("LocalMachine"):lpszServer, lpszShare); else printf("No one connected to %S\\%S\n", (lpszServer == NULL)?TEXT("\\\\LocalMachine"):lpszServer,lpszShare); } } // // Otherwise, print the error. // else printf("Error: %d\n",res); } return; }
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Lmshare.h (Windows NT/2000) or Svrapi.h (Windows 95/98); include Lm.h (Windows NT/2000).
Library: Use Netapi32.lib (Windows NT/2000) or Svrapi.lib (Windows 95/98).
Network Management Overview, Network Management Functions, Share Functions, CONNECTION_INFO_0, CONNECTION_INFO_1, connection_info_0, connection_info_1, connection_info_50