NetFileEnum function (lmshare.h)

Returns information about some or all open files on a server, depending on the parameters specified.

Syntax

NET_API_STATUS NET_API_FUNCTION NetFileEnum(
  [in]      LMSTR      servername,
  [in]      LMSTR      basepath,
  [in]      LMSTR      username,
  [in]      DWORD      level,
  [out]     LPBYTE     *bufptr,
  [in]      DWORD      prefmaxlen,
  [out]     LPDWORD    entriesread,
  [out]     LPDWORD    totalentries,
  [in, out] PDWORD_PTR resume_handle
);

Parameters

[in] servername

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.

This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined.

[in] basepath

Pointer to a string that specifies 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 the value of the basepath parameter as a prefix. (A prefix is the portion of a path that comes before a backslash.)

This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined.

[in] username

Pointer to a string that specifies the name of the user or the name of the connection. If the string begins with two backslashes ("\"), then it indicates the name of the connection, for example, "\127.0.0.1" or "\ClientName". The part of the connection name after the backslashes is the same as the client name in the session information structure returned by the NetSessionEnum function. If the string does not begin with two backslashes, then it indicates the name of the user. If this parameter is not NULL, its value serves as a qualifier for the enumeration. The files returned are limited to those that have user names or connection names that match the qualifier. If this parameter is NULL, no user-name qualifier is used.

Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP:  This parameter is a pointer to a string that specifies the name of the user. If this parameter is not NULL, its value 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.

This string is Unicode if _WIN32_WINNT or FORCE_UNICODE is defined.

[in] level

Specifies the information level of the data. This parameter can be one of the following values.

Value Meaning
2
Return the file identification number. The bufptr parameter points to an array of FILE_INFO_2 structures.
3
Return information about the file. The bufptr parameter points to an array of FILE_INFO_3 structures.

[out] bufptr

Pointer to the address of the buffer that receives the information. 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.

[in] prefmaxlen

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.

[out] entriesread

Pointer to a value that receives the count of elements actually enumerated.

[out] totalentries

Pointer to a value that receives the total number of entries that could have been enumerated from the current resume position. Note that applications should consider this value only as a hint.

[in, out] resume_handle

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 this parameter is NULL, no resume handle is stored.

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 Description
ERROR_ACCESS_DENIED
The user does not have access to the requested information.
ERROR_INVALID_LEVEL
The value specified for the level parameter is not valid.
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

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

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.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header lmshare.h (include Lm.h)
Library Netapi32.lib
DLL Netapi32.dll

See also

FILE_INFO_2

FILE_INFO_3

NetFile Functions

NetFileGetInfo

Network Management Functions

Network Management Overview