Platform SDK: Network Management |
The NetDfsEnum function enumerates all the Distributed File System (Dfs) links in the named Dfs root. The function returns information about the Dfs links based on information specified by the Level parameter.
No special group membership is required to successfully execute the NetDfsEnum function.
NET_API_STATUS NetDfsEnum( LPWSTR DfsName, // name of the Dfs for enumeration DWORD Level, // level of information requested DWORD PrefMaxLen, // advisory, but -1 means return // all information LPBYTE *Buffer, // function allocates and returns the // buffer with requested info LPDWORD EntriesRead, // number of entries returned LPDWORD ResumeHandle // must be 0 on first call, reused // on subsequent calls );
Value | Meaning |
---|---|
1 | Return Dfs link names. The Buffer parameter points to an array of DFS_INFO_1 structures. |
2 | Return Dfs link names and additional information. The Buffer parameter points to an array of DFS_INFO_2 structures. |
3 | Return Dfs link information and share information. The Buffer parameter points to an array of DFS_INFO_3 structures. |
4 | Return Dfs link information, share information, and storage-specific information. The Buffer parameter points to an array of DFS_INFO_4 structures. |
200 | Return the name associated with the root of a domain-based Dfs implementation. The Buffer parameter points to an array of DFS_INFO_200 structures. |
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.
Call the NetDfsEnum function with the ResumeHandle parameter set to zero to begin the enumeration. To retrieve information about additional Dfs links, call the function with the ResumeHandle returned by the previous call to NetDfsEnum.
The NetDfsEnum function allocates the memory required for the information structure buffer. If you specify an amount in the PrefMaxLen parameter, it restricts the number of bytes that the function returns. However, the actual size of the memory that the NetDfsEnum function allocates can be greater than the amount you specify. For additional information see Network Management Function Buffer Lengths.
You can use the PrefMaxLen value for performance tuning. For example, if you call the function to fill a list box, and the list box can hold only 10 entries, a reasonable value for PrefMaxLen might be 12 * sizeof(DFS_INFO_n).
The following code sample demonstrates how to list the Dfs links in a named Dfs root with a call to the NetDfsEnum function. The sample calls NetDfsEnum, specifying information level 3 (DFS_INFO_3). The sample code loops through the entries and prints the retrieved data and the status of each storage server referenced by the Dfs link. Finally, the sample frees the memory allocated for the information buffer.
#define UNICODE #include <windows.h> #include <lm.h> #include <lmdfs.h> #include <stdio.h> void wmain(int argc, wchar_t *argv[ ]) { PDFS_INFO_3 pData, p; PDFS_STORAGE_INFO ps; DWORD er=0, tr=0, res, i, j; if(argc<2) wprintf(L"Syntax: %s \\\\DfsName\n", argv[0]); else { // // Call the NetDfsEnum function, specifying level 3. // res = NetDfsEnum(argv[1], 3, 0xFFFFFFFF, (LPBYTE *) &pData, &er, &tr); // // If no error occurred, // if(res==0) { p=pData; // // Loop through the entries; print the data. // for(i=1;i<=er;i++) { printf("%-30S%u\n",p->EntryPath, p->NumberOfStorages); ps = p->Storage; // // Loop through each storage. // for(j=1;j<=p->NumberOfStorages;j++) { // // Print the status (Offline/Online) and the name // of each storage referenced by the Dfs link. // printf(" %S ", (ps->State == DFS_STORAGE_STATE_OFFLINE) ? TEXT("Offline"):TEXT("Online ")); printf("\\\\%S\\%S\n",ps->ServerName,ps->ShareName); ps++; } p++; } // Free the allocated buffer. // NetApiBufferFree(pData); } // // Otherwise, print the error. // else printf("Error: %u\n", res); } return; }
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Unsupported.
Header: Declared in Lmdfs.h; include Lm.h.
Library: Use Netapi32.lib.
Network Management Overview, Network Management Functions, Distributed File System (Dfs) Functions, DFS_INFO_1, DFS_INFO_2, DFS_INFO_3, DFS_INFO_4, DFS_INFO_200, NetDfsAdd, NetDfsRemove