Platform SDK: Network Management

NetFileEnum

The NetFileEnum function returns information about some or all open files on a server, depending on the parameters specified.

Security Requirements

Only members of the Administrators or Account Operators local group can successfully execute the NetFileEnum function.

Windows NT/2000: The parameter order is as follows.

NET_API_STATUS NetFileEnum(
  LPWSTR servername,     
  LPWSTR basepath,       
  LPWSTR username,       
  DWORD level,           
  LPBYTE *bufptr,        
  DWORD prefmaxlen,      
  LPDWORD entriesread,   
  LPDWORD totalentries,  
  PDWORD_PTR 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.) Neither a user name parameter nor a resume handle parameter is available on this platform. Therefore, the parameter list is as follows.

extern API_FUNCTION
 NetFileEnum(
  const char FAR * pszServer,        
  const char FAR * pszBasePath,      
  short sLevel,                      
  char FAR * pbBuffer,               
  unsigned short  cbBuffer,          
  unsigned short FAR * pcEntriesRead,
  unsigned short FAR * pcTotalAvail  
);

Parameters

servername
[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
basepath
[in] Pointer to a Unicode (Windows NT/2000) or ANSI (Windows 95/98) string specifying a qualifier for the returned information. If this parameter is NULL, all open resources are enumerated. If this parameter is not NULL, the function enumerates only resources that have basepath as a prefix. (A prefix is the path component up to a backslash.)
username
[in] Pointer to a Unicode string that specifies the name of the user. If this parameter is specified, username serves as a qualifier for the enumeration. The files returned are limited to those that have user names matching the qualifier. If this parameter is NULL, no user-name qualifier is used.
level
[in] Specifies the information level of the data. This parameter can be one of the following values.
Value Meaning
2 Windows NT/2000: Return the file identification number. The bufptr parameter points to an array of FILE_INFO_2 structures.
3 Windows NT/2000: Return information about the file. The bufptr parameter points to an array of FILE_INFO_3 structures.
50 Windows 95/98: Return information about the file. The returned buffer contains an array of file_info_50 structures.

bufptr
[out] Pointer to the address of the buffer that receives the information. The format of this data depends on the value of the level parameter.

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.

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.
resume_handle
[in/out] Pointer to a value that contains a resume handle which is used to continue an existing file search. The handle should be zero on the first call and left unchanged for subsequent calls. If resume_handle is NULL, then no resume handle is stored.

Return Values

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.

Value Meaning
ERROR_ACCESS_DENIED The user does not have access to the requested information.
ERROR_INVALID_LEVEL The value specified for the level parameter is invalid.
ERROR_MORE_DATA More entries are available. Specify a large enough buffer to receive all entries.
ERROR_NOT_ENOUGH_MEMORY Insufficient memory is available.
NERR_BufTooSmall The supplied buffer is too small.

Remarks

You can call the NetFileGetInfo function to retrieve information about a particular opening of a server resource.

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 NetFileEnum. For more information, see IADsResource and IADsFileServiceOperations.

Windows 95/98: See the NetFileEnum Sample (Windows 95/98) topic to view a code sample that demonstrates how to use the NetFileEnum function.

Requirements

  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).

See Also

Network Management Overview, Network Management Functions, NetFile Functions, FILE_INFO_2, FILE_INFO_3, file_info_50, NetFileGetInfo