WNetOpenEnum

This API is used to open an enumeration of network resources or existing connections. It must be called to obtain a valid handle for enumeration.


DWORD WNetOpenEnum (
    DWORD dwScope,
    DWORD dwType,
    DWORD dwUsage,
    LPNETRESOURCE lpNetResource,
    LPHANDLE lphEnum
    );

dwScope

Determines the scope of the enumeration. This can be one of:

RESOURCE_CONNECTED

All currently connected resources - this does not include persistent connections that are not currently available.

RESOURCE_GLOBALNET

All resources on the network.

RESOURCE_REMEMBERED

All persistent connections.

RESOURCE_RECENT

The most recent connections made.

RESOURCE_CONTEXT

The resources associated with the user's current and default network context.


dwType

Used to specify the type of resources and level of detail of interest. This is a bit mask which may be any combination of:

RESOURCETYPE_DISK

All disk resources.

RESOURCETYPE_PRINT

All print resources.


If dwType is RESOURCETYPE_ANY, all types of resources are returned. If an NP does not have the capability to distinguish between print and disk resources at a level, it may return all resources.

dwUsage

Used to specify the usage of resources of interest. This is a bit mask which may be any combination of:

RESOURCEUSAGE_CONNECTABLE

All connectable resources.

RESOURCEUSAGE_CONTAINER

All container resources.

RESOURCEUSAGE_ALL

All resources.


This field is ignored if dwScope is not RESOURCE_GLOBALNET.

lpNetResource

This specifies the container upon which to perform the enumeration. The NETRESOURCE could have been obtained via WNetEnumResource, constructed by the caller, or NULL. If it is NULL, the logical root of the network is assumed. An application would normally start off by calling WNetOpenEnum with this parameter set to NULL, and then use the returned results for further enumeration. If the calling program knows exactly the NP and remote path to enumerate from, it may build its own NETRESOURCE structure to pass in, filling in the lpProvider and lpRemoteName fields.. If dwScope is RESOURCE_REMEMBERED, RESOURCE_CONNECTED, or RESOURCE_RECENT this parameter may be NULL to enumerate all networks, or an lpProvider may be used to specify a particular network, with lpLocalName and lpRemoteName being ignored.

lphEnum

If function call is successful, this will contain a handle that can then be used for WNetEnumResource.

WN_NOT_SUPPORTED

this call is specifically returned when lpNetResource specifies a provider, dwScope is RESOURCE_GLOBALNET, and the specified provider does not support browsing.

WN_NOT_CONTAINER

lpNetResource does not point to a container

WN_BAD_VALUE

Invalid dwScope or dwUsage or dwType, or bad combination of parameters is specified.

WN_FUNCTION_BUSY

The MPR or NP is busy (possibly initializing). The caller should retry.

WN_NO_NETWORK

network is not present

WN_EXTENDED_ERROR

a network specific error occurred. WNetGetLastError should be called to obtain a description of the error.

WN_NOT_AUTHENTICATED

authentication needs to occur before the network resource can be enumerated.

WN_NOT_LOGGED_ON

a system logon needs to occur before network enumeration is possible.

WN_ACCESS_DENIED

the user is authenticated to the network where the enumeration is being attempted, but does not have sufficient permissions (access rights).


If dwScope is set to RESOURCE_GLOBALNET and the lpNetResource parameter is NULL, each NETRESOURCE structure in the returned buffer will describe a network. Each entry's lpRemoteName field will be NULL (indicating the logical root of that network), and its lpProvider field will name the network. Passing such a NETRESOURCE to a further WNetOpenEnum will enumerate the top level of that particular network.

If dwScope is set to RESOURCE_CONTEXT, each NETRESOURCE structure in the returned buffer will describe a network resource that could be from any part of a network's global browse hierarchy. In addition, the first NETRESOURCE structure in the returned buffer represents a logical root for the network, and performing a WNetOpenEnum on this NETRESOURCE will enumerate the networks in the same way as above. Specifically, the NETRESOURCE structure has the following settings:

dwScope is RESOURCE_GLOBALNET

dwType is RESOURCETYPE_ANY

dwDisplayType is RESOURCEDISPLAYTYPE_ROOT

dwUsage is RESOURCEUSAGE_CONTAINER

lpLocalName, lpRemoteName, and lpProvider, are NULL

lpComment is set to a descriptive text for the root of the network