Windows Win32 Api - Wnet PDF
Windows Win32 Api - Wnet PDF
The Windows Networking (WNet) technology is not associated with any headers.
Functions
MultinetGetConnectionPerformanceA
Returns information about the expected performance of a connection used to access a network
resource. (ANSI)
MultinetGetConnectionPerformanceW
Returns information about the expected performance of a connection used to access a network
resource. (Unicode)
WNetAddConnection2A
The WNetAddConnection2 function makes a connection to a network resource and can redirect a
local device to the network resource. (ANSI)
WNetAddConnection2W
The WNetAddConnection2 function makes a connection to a network resource and can redirect a
local device to the network resource. (Unicode)
WNetAddConnection3A
The WNetAddConnection3 function makes a connection to a network resource. The function can
redirect a local device to the network resource. (ANSI)
WNetAddConnection3W
The WNetAddConnection3 function makes a connection to a network resource. The function can
redirect a local device to the network resource. (Unicode)
WNetAddConnectionA
The WNetAddConnection function enables the calling application to connect a local device to a
network resource. A successful connection is persistent, meaning that the system automatically
restores the connection during subsequent logon operations. (ANSI)
WNetAddConnectionW
The WNetAddConnection function enables the calling application to connect a local device to a
network resource. A successful connection is persistent, meaning that the system automatically
restores the connection during subsequent logon operations. (Unicode)
WNetCancelConnection2A
The WNetCancelConnection2 function cancels an existing network connection. You can also call
the function to remove remembered network connections that are not currently connected.
(ANSI)
WNetCancelConnection2W
The WNetCancelConnection2 function cancels an existing network connection. You can also call
the function to remove remembered network connections that are not currently connected.
(Unicode)
WNetCancelConnectionA
WNetCancelConnectionW
WNetCloseEnum
The WNetCloseEnum function ends a network resource enumeration started by a call to the
WNetOpenEnum function.
WNetConnectionDialog
The WNetConnectionDialog function starts a general browsing dialog box for connecting to
network resources. The function requires a handle to the owner window for the dialog box.
WNetConnectionDialog1A
WNetConnectionDialog1W
WNetDisconnectDialog
The WNetDisconnectDialog function starts a general browsing dialog box for disconnecting from
network resources. The function requires a handle to the owner window for the dialog box.
WNetDisconnectDialog1A
WNetDisconnectDialog1W
WNetEnumResourceA
WNetEnumResourceW
WNetGetConnectionA
The WNetGetConnection function retrieves the name of the network resource associated with a
local device. (ANSI)
WNetGetConnectionW
The WNetGetConnection function retrieves the name of the network resource associated with a
local device. (Unicode)
WNetGetLastErrorA
The WNetGetLastError function retrieves the most recent extended error code set by a WNet
function. The network provider reported this error code; it will not generally be one of the errors
included in the SDK header file WinError.h. (ANSI)
WNetGetLastErrorW
The WNetGetLastError function retrieves the most recent extended error code set by a WNet
function. The network provider reported this error code; it will not generally be one of the errors
included in the SDK header file WinError.h. (Unicode)
WNetGetNetworkInformationA
WNetGetNetworkInformationW
WNetGetProviderNameA
The WNetGetProviderName function obtains the provider name for a specific type of network.
(ANSI)
WNetGetProviderNameW
The WNetGetProviderName function obtains the provider name for a specific type of network.
(Unicode)
WNetGetResourceInformationA
WNetGetResourceInformationW
WNetGetResourceParentA
The WNetGetResourceParent function returns the parent of a network resource in the network
browse hierarchy. Browsing begins at the location of the specified network resource. (ANSI)
WNetGetResourceParentW
The WNetGetResourceParent function returns the parent of a network resource in the network
browse hierarchy. Browsing begins at the location of the specified network resource. (Unicode)
WNetGetUniversalNameA
The WNetGetUniversalName function takes a drive-based path for a network resource and returns
an information structure that contains a more universal form of the name. (ANSI)
WNetGetUniversalNameW
The WNetGetUniversalName function takes a drive-based path for a network resource and returns
an information structure that contains a more universal form of the name. (Unicode)
WNetGetUserA
The WNetGetUser function retrieves the current default user name, or the user name used to
establish a network connection. (ANSI)
WNetGetUserW
The WNetGetUser function retrieves the current default user name, or the user name used to
establish a network connection. (Unicode)
WNetOpenEnumA
WNetOpenEnumW
WNetRestoreConnectionW
WNetUseConnectionA
The WNetUseConnection function makes a connection to a network resource. The function can
redirect a local device to a network resource. (ANSI)
WNetUseConnectionW
The WNetUseConnection function makes a connection to a network resource. The function can
redirect a local device to a network resource. (Unicode)
Structures
CONNECTDLGSTRUCTA
CONNECTDLGSTRUCTW
DISCDLGSTRUCTA
Used in the WNetDisconnectDialog1 function. The structure contains required information for the
disconnect attempt. (ANSI)
DISCDLGSTRUCTW
Used in the WNetDisconnectDialog1 function. The structure contains required information for the
disconnect attempt. (Unicode)
NETINFOSTRUCT
Functions
MultinetGetConnectionPerformanceA
Returns information about the expected performance of a connection used to access a network
resource. (ANSI)
MultinetGetConnectionPerformanceW
Returns information about the expected performance of a connection used to access a network
resource. (Unicode)
WNetAddConnection2A
The WNetAddConnection2 function makes a connection to a network resource and can redirect a
local device to the network resource. (ANSI)
WNetAddConnection2W
The WNetAddConnection2 function makes a connection to a network resource and can redirect a
local device to the network resource. (Unicode)
WNetAddConnection3A
The WNetAddConnection3 function makes a connection to a network resource. The function can
redirect a local device to the network resource. (ANSI)
WNetAddConnection3W
The WNetAddConnection3 function makes a connection to a network resource. The function can
redirect a local device to the network resource. (Unicode)
WNetAddConnectionA
The WNetAddConnection function enables the calling application to connect a local device to a
network resource. A successful connection is persistent, meaning that the system automatically
restores the connection during subsequent logon operations. (ANSI)
WNetAddConnectionW
The WNetAddConnection function enables the calling application to connect a local device to a
network resource. A successful connection is persistent, meaning that the system automatically
restores the connection during subsequent logon operations. (Unicode)
WNetCancelConnection2A
The WNetCancelConnection2 function cancels an existing network connection. You can also call
the function to remove remembered network connections that are not currently connected.
(ANSI)
WNetCancelConnection2W
The WNetCancelConnection2 function cancels an existing network connection. You can also call
the function to remove remembered network connections that are not currently connected.
(Unicode)
WNetCancelConnectionA
WNetCancelConnectionW
WNetCloseEnum
The WNetCloseEnum function ends a network resource enumeration started by a call to the
WNetOpenEnum function.
WNetConnectionDialog
The WNetConnectionDialog function starts a general browsing dialog box for connecting to
network resources. The function requires a handle to the owner window for the dialog box.
WNetConnectionDialog1A
WNetConnectionDialog1W
WNetDisconnectDialog
The WNetDisconnectDialog function starts a general browsing dialog box for disconnecting from
network resources. The function requires a handle to the owner window for the dialog box.
WNetDisconnectDialog1A
WNetDisconnectDialog1W
WNetEnumResourceA
WNetEnumResourceW
WNetGetConnectionA
The WNetGetConnection function retrieves the name of the network resource associated with a
local device. (ANSI)
WNetGetConnectionW
The WNetGetConnection function retrieves the name of the network resource associated with a
local device. (Unicode)
WNetGetLastErrorA
The WNetGetLastError function retrieves the most recent extended error code set by a WNet
function. The network provider reported this error code; it will not generally be one of the errors
included in the SDK header file WinError.h. (ANSI)
WNetGetLastErrorW
The WNetGetLastError function retrieves the most recent extended error code set by a WNet
function. The network provider reported this error code; it will not generally be one of the errors
included in the SDK header file WinError.h. (Unicode)
WNetGetNetworkInformationA
WNetGetNetworkInformationW
WNetGetProviderNameA
The WNetGetProviderName function obtains the provider name for a specific type of network.
(ANSI)
WNetGetProviderNameW
The WNetGetProviderName function obtains the provider name for a specific type of network.
(Unicode)
WNetGetResourceInformationA
WNetGetResourceInformationW
WNetGetResourceParentA
The WNetGetResourceParent function returns the parent of a network resource in the network
browse hierarchy. Browsing begins at the location of the specified network resource. (ANSI)
WNetGetResourceParentW
The WNetGetResourceParent function returns the parent of a network resource in the network
browse hierarchy. Browsing begins at the location of the specified network resource. (Unicode)
WNetGetUniversalNameA
The WNetGetUniversalName function takes a drive-based path for a network resource and returns
an information structure that contains a more universal form of the name. (ANSI)
WNetGetUniversalNameW
The WNetGetUniversalName function takes a drive-based path for a network resource and returns
an information structure that contains a more universal form of the name. (Unicode)
WNetGetUserA
The WNetGetUser function retrieves the current default user name, or the user name used to
establish a network connection. (ANSI)
WNetGetUserW
The WNetGetUser function retrieves the current default user name, or the user name used to
establish a network connection. (Unicode)
WNetOpenEnumA
WNetOpenEnumW
WNetRestoreConnectionW
WNetUseConnectionA
The WNetUseConnection function makes a connection to a network resource. The function can
redirect a local device to a network resource. (ANSI)
WNetUseConnectionW
The WNetUseConnection function makes a connection to a network resource. The function can
redirect a local device to a network resource. (Unicode)
Structures
CONNECTDLGSTRUCTA
CONNECTDLGSTRUCTW
DISCDLGSTRUCTA
Used in the WNetDisconnectDialog1 function. The structure contains required information for the
disconnect attempt. (ANSI)
DISCDLGSTRUCTW
Used in the WNetDisconnectDialog1 function. The structure contains required information for the
disconnect attempt. (Unicode)
NETCONNECTINFOSTRUCT
NETINFOSTRUCT
NETRESOURCEA
The following structure contains information about a network resource. It is used by several of the
network provider functions, including NPOpenEnum and NPAddConnection. (ANSI)
NETRESOURCEW
The following structure contains information about a network resource. It is used by several of the
network provider functions, including NPOpenEnum and NPAddConnection. (Unicode)
REMOTE_NAME_INFOA
The REMOTE_NAME_INFO structure contains information about the remote form of a universal
name. It is used by the NPGetUniversalName function. (ANSI)
REMOTE_NAME_INFOW
The REMOTE_NAME_INFO structure contains information about the remote form of a universal
name. It is used by the NPGetUniversalName function. (Unicode)
UNIVERSAL_NAME_INFOA
The UNIVERSAL_NAME_INFO structure contains information about the UNC form of a universal
name. It is used by the NPGetUniversalName function. (ANSI)
UNIVERSAL_NAME_INFOW
The UNIVERSAL_NAME_INFO structure contains information about the UNC form of a universal
name. It is used by the NPGetUniversalName function. (Unicode)
CONNECTDLGSTRUCTA structure
(winnetwk.h)
Article • 07/27/20222 minutes to read
The
CONNECTDLGSTRUCT structure is used by the
WNetConnectionDialog1 function to
establish browsing dialog box parameters.
Syntax
DWORD cbStructure;
HWND hwndOwner;
LPNETRESOURCEA lpConnRes;
DWORD dwFlags;
DWORD dwDevNum;
} CONNECTDLGSTRUCTA, *LPCONNECTDLGSTRUCTA;
Members
cbStructure
Type: DWORD
hwndOwner
Type: HWND
lpConnRes
Type: LPNETRESOURCE
A pointer to a
NETRESOURCE structure.
The system does not support the RESOURCETYPE_PRINT flag for browsing and
connecting to print resources.
dwFlags
Type: DWORD
A set of bit flags that describe options for the dialog box display. This member can be a
combination of the following values.
Value Meaning
CONNDLG_USE_MRU Enter the most recently used paths into the combination
box. Set this value to simulate the
WNetConnectionDialog function.
CONNDLG_HIDE_BOX Show the check box allowing the user to restore the
connection at logon.
dwDevNum
Type: DWORD
7 Note
Requirements
Header winnetwk.h
See also
NETRESOURCE
WNetConnectionDialog1
The
CONNECTDLGSTRUCT structure is used by the
WNetConnectionDialog1 function to
establish browsing dialog box parameters.
Syntax
C++
DWORD cbStructure;
HWND hwndOwner;
LPNETRESOURCEW lpConnRes;
DWORD dwFlags;
DWORD dwDevNum;
} CONNECTDLGSTRUCTW, *LPCONNECTDLGSTRUCTW;
Members
cbStructure
Type: DWORD
hwndOwner
Type: HWND
lpConnRes
Type: LPNETRESOURCE
A pointer to a
NETRESOURCE structure.
The system does not support the RESOURCETYPE_PRINT flag for browsing and
connecting to print resources.
dwFlags
Type: DWORD
A set of bit flags that describe options for the dialog box display. This member can be a
combination of the following values.
Value Meaning
CONNDLG_USE_MRU Enter the most recently used paths into the combination
box. Set this value to simulate the
WNetConnectionDialog function.
CONNDLG_HIDE_BOX Show the check box allowing the user to restore the
connection at logon.
dwDevNum
Type: DWORD
7 Note
Requirements
Header winnetwk.h
See also
NETRESOURCE
WNetConnectionDialog1
The
DISCDLGSTRUCT structure is used in the
WNetDisconnectDialog1 function. The
structure contains required information for the disconnect attempt.
Syntax
C++
DWORD cbStructure;
HWND hwndOwner;
LPSTR lpLocalName;
LPSTR lpRemoteName;
DWORD dwFlags;
} DISCDLGSTRUCTA, *LPDISCDLGSTRUCTA;
Members
cbStructure
Type: DWORD
hwndOwner
Type: HWND
lpLocalName
Type: LPTSTR
A pointer to a NULL-terminated string that specifies the local device name that is
redirected to the network resource, such as "F:" or "LPT1".
lpRemoteName
Type: LPTSTR
A pointer to a NULL-terminated string that specifies the name of the network resource
to disconnect. This member can be NULL if the lpLocalName member is specified. When
lpLocalName is specified, the connection to the network resource redirected from
lpLocalName is disconnected.
dwFlags
Type: DWORD
A set of bit flags describing the connection. This member can be a combination of the
following values.
Value Meaning
DISC_NO_FORCE If this value is not set, the system applies force when
attempting to disconnect from the network resource.
This situation typically occurs when the user has files
open over the connection. This value means that the user
will be informed if there are open files on the connection,
and asked if he or she still wants to disconnect. If the user
wants to proceed, the disconnect procedure re-attempts
with additional force.
Remarks
7 Note
Requirements
Header winnetwk.h
See also
WNetDisconnectDialog1
The
DISCDLGSTRUCT structure is used in the
WNetDisconnectDialog1 function. The
structure contains required information for the disconnect attempt.
Syntax
C++
DWORD cbStructure;
HWND hwndOwner;
LPWSTR lpLocalName;
LPWSTR lpRemoteName;
DWORD dwFlags;
} DISCDLGSTRUCTW, *LPDISCDLGSTRUCTW;
Members
cbStructure
Type: DWORD
hwndOwner
Type: HWND
lpLocalName
Type: LPTSTR
A pointer to a NULL-terminated string that specifies the local device name that is
redirected to the network resource, such as "F:" or "LPT1".
lpRemoteName
Type: LPTSTR
A pointer to a NULL-terminated string that specifies the name of the network resource
to disconnect. This member can be NULL if the lpLocalName member is specified. When
lpLocalName is specified, the connection to the network resource redirected from
lpLocalName is disconnected.
dwFlags
Type: DWORD
A set of bit flags describing the connection. This member can be a combination of the
following values.
Value Meaning
DISC_NO_FORCE If this value is not set, the system applies force when
attempting to disconnect from the network resource.
This situation typically occurs when the user has files
open over the connection. This value means that the user
will be informed if there are open files on the connection,
and asked if he or she still wants to disconnect. If the user
wants to proceed, the disconnect procedure re-attempts
with additional force.
Remarks
7 Note
Requirements
Header winnetwk.h
See also
WNetDisconnectDialog1
The
MultinetGetConnectionPerformance function returns information about the
expected performance of a connection used to access a network resource.
Syntax
C++
DWORD MultinetGetConnectionPerformanceA(
);
Parameters
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies the network resource. The
following members have specific meanings in this context.
Member Meaning
[out] lpNetConnectInfoStruct
A pointer to the
NETCONNECTINFOSTRUCT structure that receives the data.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
The MultinetGetConnectionPerformance function returns the information in a
NETCONNECTINFOSTRUCT structure.
A typical way to use this function would be to open a file on a network server (which
would ensure that there is a connection to the file), call this function, and use the results
to make decisions about how to manage file I/O. For example, you can decide whether
to read the entire file into a temporary file on the client or directly access the file on the
server.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETCONNECTINFOSTRUCT
NETRESOURCE
Windows
Networking (WNet) Overview
Windows
Networking Functions
MultinetGetConnectionPerformanceW
function (winnetwk.h)
Article • 02/09/20233 minutes to read
The
MultinetGetConnectionPerformance function returns information about the
expected performance of a connection used to access a network resource.
Syntax
C++
DWORD MultinetGetConnectionPerformanceW(
);
Parameters
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies the network resource. The
following members have specific meanings in this context.
Member Meaning
[out] lpNetConnectInfoStruct
A pointer to the
NETCONNECTINFOSTRUCT structure that receives the data.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
The MultinetGetConnectionPerformance function returns the information in a
NETCONNECTINFOSTRUCT structure.
A typical way to use this function would be to open a file on a network server (which
would ensure that there is a connection to the file), call this function, and use the results
to make decisions about how to manage file I/O. For example, you can decide whether
to read the entire file into a temporary file on the client or directly access the file on the
server.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETCONNECTINFOSTRUCT
NETRESOURCE
Windows
Networking (WNet) Overview
Windows
Networking Functions
NETINFOSTRUCT structure (winnetwk.h)
Article • 04/02/20212 minutes to read
The
NETINFOSTRUCT structure contains information describing the network provider
returned by the
WNetGetNetworkInformation function.
Syntax
C++
DWORD cbStructure;
DWORD dwProviderVersion;
DWORD dwStatus;
DWORD dwCharacteristics;
ULONG_PTR dwHandle;
WORD wNetType;
DWORD dwPrinters;
DWORD dwDrives;
} NETINFOSTRUCT, *LPNETINFOSTRUCT;
Members
cbStructure
Type: DWORD
dwProviderVersion
Type: DWORD
dwStatus
Type: DWORD
The current status of the network provider software. This member can be one of the
following values.
Value Meaning
dwCharacteristics
Type: DWORD
Value Meaning
dwHandle
Type: ULONG_PTR
An instance handle for the network provider or for the 16-bit Windows network driver.
wNetType
Type: WORD
The network type unique to the running network. This value associates resources with a
specific network when the resources are persistent or stored in links. You can find a
complete list of network types in the header file Winnetwk.h.
dwPrinters
Type: DWORD
A set of bit flags indicating the valid print numbers for redirecting local printer devices,
with the low-order bit corresponding to LPT1.
dwDrives
Type: DWORD
A set of bit flags indicating the valid local disk devices for redirecting disk drives, with
the low-order bit corresponding to A:.
Remarks
The NETINFOSTRUCT structure contains information describing the network, such as
the version of the network provider software and the network's current status.
Requirements
Header winnetwk.h
See also
WNetGetNetworkInformation
The
WNetAddConnection2 function makes a connection to a network resource and can
redirect a local device to the network resource.
The
WNetAddConnection2 function supersedes the
WNetAddConnection function. If
you can pass a handle to a window that the provider of network resources can use as an
owner window for dialog boxes, call the
WNetAddConnection3 function instead.
Syntax
C++
DWORD WNetAddConnection2A(
);
Parameters
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies details of the proposed
connection, such as information about the network resource, the local device, and the
network resource provider.
Member Meaning
You should set this member only if you know the network
provider you want to use. Otherwise, let the operating
system determine which provider the network name
maps to.
The
WNetAddConnection2 function ignores the other members of the
NETRESOURCE
structure.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by the lpUserName parameter.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserName
A pointer to a constant null-terminated string that specifies a user name for making the
connection.
If lpUserName is NULL, the function uses the default user name. (The user context for
the process provides the default user name.)
[in] dwFlags
A set of connection options. The possible values for the connection options are defined
in the Winnetwk.h header file.
The following values can currently be used.
Value Meaning
If this bit flag is clear, the operating system does not try
to restore the connection when the user logs on.
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
0x00000008 the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
0x00000010 settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_CURRENT_MEDIA If this flag is set, then the operating system does not start
0x00000200 to use a new media to try to establish the connection
(initiate a new dial up connection, for example).
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
0x00000800 for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows XP: This value is supported on Windows XP
and later.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
0x00001000 credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is ignored unless CONNECT_INTERACTIVE is also
set. This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows XP: This value is supported on Windows XP
and later.
CONNECT_CRED_RESET If this flag is set, and the operating system prompts for a
0x00002000 credential, the credential is reset by the credential
manager. If the credential manager is disabled for the
caller's logon session, or if the network provider does not
support saving credentials, this flag is ignored. This flag is
also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows Vista: This value is supported on
Windows Vista and later.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value can be one of the following error codes or one of
the
system error codes.
Remarks
On Windows Server 2003 and Windows XP, the WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID (a
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection2 function, then the mapped drive is visible to all user logon
sessions.
\192.168.1.1\share
2001:4898:9:3:c069:aa97:fe76:2449
\2001-4898-9-3-c069-aa97-fe76-2449.ipv6-literal.net\share
Examples
The following code sample illustrates how to use the
WNetAddConnection2 function to
make connection to a network resource.
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
NETRESOURCE nr;
DWORD dwFlags;
if (argc != 5) {
argv[0]);
argv[0]);
exit(1);
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = argv[1];
nr.lpRemoteName = argv[2];
nr.lpProvider = NULL;
dwFlags = CONNECT_UPDATE_PROFILE;
//
//
//
if (dwRetVal == NO_ERROR)
else
exit(1);
For other code samples that illustrates how to make a connection to a network resource
using the
WNetAddConnection2 function, see
Adding a Network Connection and
Assigning a Drive to a Share.
7 Note
The winnetwk.h header defines WNetAddConnection2 as an alias which
automatically selects the ANSI or Unicode version of this function based on the
definition of the UNICODE preprocessor constant. Mixing usage of the encoding-
neutral alias with code that not encoding-neutral can lead to mismatches that
result in compilation or runtime errors. For more information, see Conventions for
Function Prototypes.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetAddConnection3
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetAddConnection2W function
(winnetwk.h)
Article • 02/09/202312 minutes to read
The
WNetAddConnection2 function makes a connection to a network resource and can
redirect a local device to the network resource.
The
WNetAddConnection2 function supersedes the
WNetAddConnection function. If
you can pass a handle to a window that the provider of network resources can use as an
owner window for dialog boxes, call the
WNetAddConnection3 function instead.
Syntax
C++
DWORD WNetAddConnection2W(
);
Parameters
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies details of the proposed
connection, such as information about the network resource, the local device, and the
network resource provider.
Member Meaning
You should set this member only if you know the network
provider you want to use. Otherwise, let the operating
system determine which provider the network name
maps to.
The
WNetAddConnection2 function ignores the other members of the
NETRESOURCE
structure.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by the lpUserName parameter.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserName
A pointer to a constant null-terminated string that specifies a user name for making the
connection.
If lpUserName is NULL, the function uses the default user name. (The user context for
the process provides the default user name.)
[in] dwFlags
A set of connection options. The possible values for the connection options are defined
in the Winnetwk.h header file.
The following values can currently be used.
Value Meaning
If this bit flag is clear, the operating system does not try
to restore the connection when the user logs on.
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
0x00000008 the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
0x00000010 settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_CURRENT_MEDIA If this flag is set, then the operating system does not start
0x00000200 to use a new media to try to establish the connection
(initiate a new dial up connection, for example).
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
0x00000800 for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows XP: This value is supported on Windows XP
and later.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
0x00001000 credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is ignored unless CONNECT_INTERACTIVE is also
set. This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows XP: This value is supported on Windows XP
and later.
CONNECT_CRED_RESET If this flag is set, and the operating system prompts for a
0x00002000 credential, the credential is reset by the credential
manager. If the credential manager is disabled for the
caller's logon session, or if the network provider does not
support saving credentials, this flag is ignored. This flag is
also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows Vista: This value is supported on
Windows Vista and later.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value can be one of the following error codes or one of
the
system error codes.
Remarks
On Windows Server 2003 and Windows XP, the WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID (a
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection2 function, then the mapped drive is visible to all user logon
sessions.
\192.168.1.1\share
2001:4898:9:3:c069:aa97:fe76:2449
\2001-4898-9-3-c069-aa97-fe76-2449.ipv6-literal.net\share
Examples
The following code sample illustrates how to use the
WNetAddConnection2 function to
make connection to a network resource.
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
NETRESOURCE nr;
DWORD dwFlags;
if (argc != 5) {
argv[0]);
argv[0]);
exit(1);
nr.dwType = RESOURCETYPE_ANY;
nr.lpLocalName = argv[1];
nr.lpRemoteName = argv[2];
nr.lpProvider = NULL;
dwFlags = CONNECT_UPDATE_PROFILE;
//
//
//
if (dwRetVal == NO_ERROR)
else
exit(1);
For other code samples that illustrates how to make a connection to a network resource
using the
WNetAddConnection2 function, see
Adding a Network Connection and
Assigning a Drive to a Share.
7 Note
The winnetwk.h header defines WNetAddConnection2 as an alias which
automatically selects the ANSI or Unicode version of this function based on the
definition of the UNICODE preprocessor constant. Mixing usage of the encoding-
neutral alias with code that not encoding-neutral can lead to mismatches that
result in compilation or runtime errors. For more information, see Conventions for
Function Prototypes.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetAddConnection3
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetAddConnection3A function
(winnetwk.h)
Article • 02/09/20239 minutes to read
The
WNetAddConnection3 function makes a connection to a network resource. The
function can redirect a local device to the network resource.
The
WNetAddConnection3 function is similar to the
WNetAddConnection2 function.
The main difference is that
WNetAddConnection3 has an additional parameter, a
handle to a window that the provider of network resources can use as an owner window
for dialog boxes. The
WNetAddConnection2 function and the
WNetAddConnection3
function supersede the
WNetAddConnection function.
Syntax
C++
DWORD WNetAddConnection3A(
);
Parameters
[in] hwndOwner
A handle to a window that the provider of network resources can use as an owner
window for dialog boxes. Use this parameter if you set the CONNECT_INTERACTIVE
value in the dwFlags parameter.
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies details of the proposed
connection, such as information about the network resource, the local device, and the
network resource provider.
You must specify the following members of the
NETRESOURCE structure.
Member Meaning
The
WNetAddConnection3 function ignores the other members of the
NETRESOURCE
structure.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by the lpUserName parameter.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserName
A pointer to a null-terminated string that specifies a user name for making the
connection.
If lpUserName is NULL, the function uses the default user name. (The user context for
the process provides the default user name.)
[in] dwFlags
Value Meaning
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
The
WNetUseConnection function is similar to the
WNetAddConnection3 function. The
main difference is that
WNetUseConnection can automatically select an unused local
device to redirect to the network resource.
On Windows Server 2003 and Windows XP, the WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID (a
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection3 function, then the mapped drive is visible to all user logon
sessions.
\192.168.1.1\share
2001:4898:9:3:c069:aa97:fe76:2449
\2001-4898-9-3-c069-aa97-fe76-2449.ipv6-literal.net\share
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetAddConnection2
WNetCancelConnection2
WNetGetConnection
WNetUseConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetAddConnection3W function
(winnetwk.h)
Article • 02/09/20239 minutes to read
The
WNetAddConnection3 function makes a connection to a network resource. The
function can redirect a local device to the network resource.
The
WNetAddConnection3 function is similar to the
WNetAddConnection2 function.
The main difference is that
WNetAddConnection3 has an additional parameter, a
handle to a window that the provider of network resources can use as an owner window
for dialog boxes. The
WNetAddConnection2 function and the
WNetAddConnection3
function supersede the
WNetAddConnection function.
Syntax
C++
DWORD WNetAddConnection3W(
);
Parameters
[in] hwndOwner
A handle to a window that the provider of network resources can use as an owner
window for dialog boxes. Use this parameter if you set the CONNECT_INTERACTIVE
value in the dwFlags parameter.
[in] lpNetResource
A pointer to a
NETRESOURCE structure that specifies details of the proposed
connection, such as information about the network resource, the local device, and the
network resource provider.
You must specify the following members of the
NETRESOURCE structure.
Member Meaning
The
WNetAddConnection3 function ignores the other members of the
NETRESOURCE
structure.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by the lpUserName parameter.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserName
A pointer to a null-terminated string that specifies a user name for making the
connection.
If lpUserName is NULL, the function uses the default user name. (The user context for
the process provides the default user name.)
[in] dwFlags
Value Meaning
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
The
WNetUseConnection function is similar to the
WNetAddConnection3 function. The
main difference is that
WNetUseConnection can automatically select an unused local
device to redirect to the network resource.
On Windows Server 2003 and Windows XP, the WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID (a
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection3 function, then the mapped drive is visible to all user logon
sessions.
\192.168.1.1\share
2001:4898:9:3:c069:aa97:fe76:2449
\2001-4898-9-3-c069-aa97-fe76-2449.ipv6-literal.net\share
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetAddConnection2
WNetCancelConnection2
WNetGetConnection
WNetUseConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetAddConnectionA function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetAddConnection function enables the calling application to connect a local
device to a network resource. A successful connection is persistent, meaning that the
system automatically restores the connection during subsequent logon operations.
Syntax
C++
DWORD WNetAddConnectionA(
);
Parameters
[in] lpRemoteName
[in] lpPassword
If this parameter is NULL, the default password is used. If the string is empty, no
password is used.
A pointer to a constant null-terminated string that specifies the name of a local device
to be redirected, such as "F:" or "LPT1". The string is treated in a case-insensitive
manner. If the string is NULL, a connection to the network resource is made without
redirecting the local device.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_BAD_DEV_TYPE The device type and the resource type do not match.
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection function, then the mapped drive is visible to all user logon
sessions.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetCancelConnection
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetAddConnectionW function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetAddConnection function enables the calling application to connect a local
device to a network resource. A successful connection is persistent, meaning that the
system automatically restores the connection during subsequent logon operations.
Syntax
C++
DWORD WNetAddConnectionW(
);
Parameters
[in] lpRemoteName
[in] lpPassword
If this parameter is NULL, the default password is used. If the string is empty, no
password is used.
A pointer to a constant null-terminated string that specifies the name of a local device
to be redirected, such as "F:" or "LPT1". The string is treated in a case-insensitive
manner. If the string is NULL, a connection to the network resource is made without
redirecting the local device.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_BAD_DEV_TYPE The device type and the resource type do not match.
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. The call to the
GetLogicalDrives function does not return network drive letters created by WNet
function calls under the first logon. Note that in the preceding example the first logon
session still exists, and the example could apply to any logon session, including a
Terminal Services session. For more information, see
Defining an MS-DOS Device Name.
On Windows Server 2003 and Windows XP, if a service that runs as LocalSystem calls the
WNetAddConnection function, then the mapped drive is visible to all user logon
sessions.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetCancelConnection
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetCancelConnection2A function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetCancelConnection2 function cancels an existing network connection. You can
also call the function to remove remembered network connections that are not currently
connected.
The
WNetCancelConnection2 function supersedes the
WNetCancelConnection function.
Syntax
C++
DWORD WNetCancelConnection2A(
);
Parameters
[in] lpName
Pointer to a constant null-terminated string that specifies the name of either the
redirected local device or the remote network resource to disconnect from.
If this parameter specifies a redirected local device, the function cancels only the
specified device redirection. If the parameter specifies a remote network resource, all
connections without devices are canceled.
[in] dwFlags
Value Meaning
CONNECT_UPDATE_PROFILE The system updates the user profile with the information
that the connection is no longer a persistent one.
The system will not restore this connection during
subsequent logon operations. (Disconnecting resources
using remote names has no effect on persistent
connections.)
[in] fForce
Specifies whether the disconnection should occur if there are open files or jobs on the
connection. If this parameter is FALSE, the function fails if there are open files or jobs.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_OPEN_FILES There are open files, and the fForce parameter is FALSE.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
Examples
For a code sample that illustrates how to cancel a connection to a network resource with
a call to the
WNetCancelConnection2 function, see
Canceling a Network Connection.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetCancelConnection2W function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetCancelConnection2 function cancels an existing network connection. You can
also call the function to remove remembered network connections that are not currently
connected.
The
WNetCancelConnection2 function supersedes the
WNetCancelConnection function.
Syntax
C++
DWORD WNetCancelConnection2W(
);
Parameters
[in] lpName
Pointer to a constant null-terminated string that specifies the name of either the
redirected local device or the remote network resource to disconnect from.
If this parameter specifies a redirected local device, the function cancels only the
specified device redirection. If the parameter specifies a remote network resource, all
connections without devices are canceled.
[in] dwFlags
Value Meaning
CONNECT_UPDATE_PROFILE The system updates the user profile with the information
that the connection is no longer a persistent one.
The system will not restore this connection during
subsequent logon operations. (Disconnecting resources
using remote names has no effect on persistent
connections.)
[in] fForce
Specifies whether the disconnection should occur if there are open files or jobs on the
connection. If this parameter is FALSE, the function fails if there are open files or jobs.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_OPEN_FILES There are open files, and the fForce parameter is FALSE.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
Examples
For a code sample that illustrates how to cancel a connection to a network resource with
a call to the
WNetCancelConnection2 function, see
Canceling a Network Connection.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetCancelConnectionA function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetCancelConnection function cancels an existing network connection.
The
WNetCancelConnection function is provided for compatibility with 16-bit versions
of Windows. Other Windows-based applications should call the
WNetCancelConnection2 function.
Syntax
C++
DWORD WNetCancelConnectionA(
);
Parameters
[in] lpName
Pointer to a constant null-terminated string that specifies the name of either the
redirected local device or the remote network resource to disconnect from.
When this parameter specifies a redirected local device, the function cancels only the
specified device redirection. If the parameter specifies a remote network resource, only
the connections to remote networks without devices are canceled.
[in] fForce
Specifies whether or not the disconnection should occur if there are open files or jobs
on the connection. If this parameter is FALSE, the function fails if there are open files or
jobs.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a
system error code, such as one of the following
values.
ERROR_OPEN_FILES There are open files, and the fForce parameter is FALSE.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection
WNetAddConnection2
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetCancelConnectionW function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetCancelConnection function cancels an existing network connection.
The
WNetCancelConnection function is provided for compatibility with 16-bit versions
of Windows. Other Windows-based applications should call the
WNetCancelConnection2 function.
Syntax
C++
DWORD WNetCancelConnectionW(
);
Parameters
[in] lpName
Pointer to a constant null-terminated string that specifies the name of either the
redirected local device or the remote network resource to disconnect from.
When this parameter specifies a redirected local device, the function cancels only the
specified device redirection. If the parameter specifies a remote network resource, only
the connections to remote networks without devices are canceled.
[in] fForce
Specifies whether or not the disconnection should occur if there are open files or jobs
on the connection. If this parameter is FALSE, the function fails if there are open files or
jobs.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a
system error code, such as one of the following
values.
ERROR_OPEN_FILES There are open files, and the fForce parameter is FALSE.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection
WNetAddConnection2
WNetCancelConnection2
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetCloseEnum function (winnetwk.h)
Article • 10/13/20212 minutes to read
The
WNetCloseEnum function ends a network resource enumeration started by a call to
the
WNetOpenEnum function.
Syntax
C++
DWORD WNetCloseEnum(
);
Parameters
[in] hEnum
Handle that identifies an enumeration instance. This handle must be returned by the
WNetOpenEnum function.
Return value
If the function succeeds, the return value is NO_ERROR.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetEnumResource
WNetOpenEnum
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetConnectionDialog function
(winnetwk.h)
Article • 10/13/20212 minutes to read
The
WNetConnectionDialog function starts a general browsing dialog box for
connecting to network resources. The function requires a handle to the owner window
for the dialog box.
Syntax
C++
DWORD WNetConnectionDialog(
);
Parameters
[in] hwnd
[in] dwType
Resource type to allow connections to. This parameter can be the following value.
Value Meaning
Return value
If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog
box, the function returns –1.
Remarks
If the user clicks OK in the dialog box, the requested network connection will have been
made when the
WNetConnectionDialog function returns.
If the function attempts to make a connection and the network provider returns the
message ERROR_INVALID_PASSWORD, the system prompts the user to enter a
password. The system uses the new password in another attempt to make the
connection.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection3
WNetCancelConnection2
WNetDisconnectDialog
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetConnectionDialog1A function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetConnectionDialog1 function brings up a general browsing dialog for
connecting to network resources. The function requires a
CONNECTDLGSTRUCT to
establish the dialog box parameters.
Syntax
C++
DWORD WNetConnectionDialog1A(
);
Parameters
[in, out] lpConnDlgStruct
Pointer to a
CONNECTDLGSTRUCT structure. The structure establishes the browsing
dialog parameters.
Return value
If the user cancels the dialog box, the function returns –1. If the function is successful, it
returns NO_ERROR. Also, if the call is successful, the dwDevNum member of the
CONNECTDLGSTRUCT structure contains the number of the connected device.
Typically this dialog returns an error only if the user cannot enter a dialog session. This is
because errors that occur after a dialog session are reported to the user directly. If the
function fails, the return value is a
system error code, such as one of the following
values.
-or-
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
CONNECTDLGSTRUCT
NETRESOURCE
WNetConnectionDialog
WNetDisconnectDialog
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetConnectionDialog1W function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetConnectionDialog1 function brings up a general browsing dialog for
connecting to network resources. The function requires a
CONNECTDLGSTRUCT to
establish the dialog box parameters.
Syntax
C++
DWORD WNetConnectionDialog1W(
);
Parameters
[in, out] lpConnDlgStruct
Pointer to a
CONNECTDLGSTRUCT structure. The structure establishes the browsing
dialog parameters.
Return value
If the user cancels the dialog box, the function returns –1. If the function is successful, it
returns NO_ERROR. Also, if the call is successful, the dwDevNum member of the
CONNECTDLGSTRUCT structure contains the number of the connected device.
Typically this dialog returns an error only if the user cannot enter a dialog session. This is
because errors that occur after a dialog session are reported to the user directly. If the
function fails, the return value is a
system error code, such as one of the following
values.
-or-
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
CONNECTDLGSTRUCT
NETRESOURCE
WNetConnectionDialog
WNetDisconnectDialog
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetDisconnectDialog function
(winnetwk.h)
Article • 10/13/20212 minutes to read
The
WNetDisconnectDialog function starts a general browsing dialog box for
disconnecting from network resources. The function requires a handle to the owner
window for the dialog box.
Syntax
C++
DWORD WNetDisconnectDialog(
);
Parameters
[in] hwnd
[in] dwType
Resource type to disconnect from. This parameter can have the following value.
Value Meaning
Return value
If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog
box, the return value is –1.
Remarks
The
WNetDisconnectDialog function returns immediately and creates a dialog box for
disconnecting networked drives. This dialog box runs asynchronously on a worker
thread.
If the worker thread is terminated, the owner window and its associated dialog box are
also terminated. If this occurs, the user might not be able to interact with the dialog box,
because it will not appear on the user's screen or will appear briefly.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetCancelConnection2
WNetConnectionDialog
WNetConnectionDialog1
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetDisconnectDialog1A function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetDisconnectDialog1 function attempts to disconnect a network resource. If the
underlying network returns ERROR_OPEN_FILES, the function prompts the user for
confirmation. If there is any error, the function informs the user. The function requires a
DISCDLGSTRUCT to specify the parameters for the disconnect attempt.
Syntax
C++
DWORD WNetDisconnectDialog1A(
);
Parameters
[in] lpConnDlgStruct
Pointer to a
DISCDLGSTRUCT structure. The structure specifies the behavior for the
disconnect attempt.
Return value
If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog
box, the return value is –1.
ERROR_CANCELLED When the system prompted the user for a decision about
disconnecting, the user elected not to disconnect.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
DISCDLGSTRUCT
WNetConnectionDialog
WNetConnectionDialog1
WNetDisconnectDialog
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetDisconnectDialog1W function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetDisconnectDialog1 function attempts to disconnect a network resource. If the
underlying network returns ERROR_OPEN_FILES, the function prompts the user for
confirmation. If there is any error, the function informs the user. The function requires a
DISCDLGSTRUCT to specify the parameters for the disconnect attempt.
Syntax
C++
DWORD WNetDisconnectDialog1W(
);
Parameters
[in] lpConnDlgStruct
Pointer to a
DISCDLGSTRUCT structure. The structure specifies the behavior for the
disconnect attempt.
Return value
If the function succeeds, the return value is NO_ERROR. If the user cancels the dialog
box, the return value is –1.
ERROR_CANCELLED When the system prompted the user for a decision about
disconnecting, the user elected not to disconnect.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
DISCDLGSTRUCT
WNetConnectionDialog
WNetConnectionDialog1
WNetDisconnectDialog
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetEnumResourceA function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetEnumResource function continues an enumeration of network resources that
was started by a call to the
WNetOpenEnum function.
Syntax
C++
DWORD WNetEnumResourceA(
);
Parameters
[in] hEnum
Handle that identifies an enumeration instance. This handle must be returned by the
WNetOpenEnum function.
If the function succeeds, on return the variable pointed to by this parameter contains
the number of entries actually read.
[out] lpBuffer
Pointer to the buffer that receives the enumeration results. The results are returned as
an array of
NETRESOURCE structures. Note that the buffer you allocate must be large
enough to hold the structures, plus the strings to which their members point. For more
information, see the following Remarks section.
The buffer is valid until the next call using the handle specified by the hEnum parameter.
The order of
NETRESOURCE structures in the array is not predictable.
[in, out] lpBufferSize
Pointer to a variable that specifies the size of the lpBuffer parameter, in bytes. If the
buffer is too small to receive even one entry, this parameter receives the required size of
the buffer.
Return value
If the function succeeds, the return value is one of the following values.
Remarks
The
WNetEnumResource function does not enumerate users connected to a share; you
can call the
NetConnectionEnum function to accomplish this task. To enumerate hidden
shares, call the
NetShareEnum function.
An application cannot set the lpBuffer parameter to NULL and retrieve the required
buffer size from the lpBufferSize parameter. Instead, the application should allocate a
buffer of a reasonable size—16 kilobytes is typical—and use the value of lpBufferSize for
error detection.
Examples
For a code sample that illustrates an application-defined function that enumerates all
the resources on a network, see
Enumerating Network Resources.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetCloseEnum
WNetOpenEnum
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetEnumResourceW function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetEnumResource function continues an enumeration of network resources that
was started by a call to the
WNetOpenEnum function.
Syntax
C++
DWORD WNetEnumResourceW(
);
Parameters
[in] hEnum
Handle that identifies an enumeration instance. This handle must be returned by the
WNetOpenEnum function.
If the function succeeds, on return the variable pointed to by this parameter contains
the number of entries actually read.
[out] lpBuffer
Pointer to the buffer that receives the enumeration results. The results are returned as
an array of
NETRESOURCE structures. Note that the buffer you allocate must be large
enough to hold the structures, plus the strings to which their members point. For more
information, see the following Remarks section.
The buffer is valid until the next call using the handle specified by the hEnum parameter.
The order of
NETRESOURCE structures in the array is not predictable.
[in, out] lpBufferSize
Pointer to a variable that specifies the size of the lpBuffer parameter, in bytes. If the
buffer is too small to receive even one entry, this parameter receives the required size of
the buffer.
Return value
If the function succeeds, the return value is one of the following values.
Remarks
The
WNetEnumResource function does not enumerate users connected to a share; you
can call the
NetConnectionEnum function to accomplish this task. To enumerate hidden
shares, call the
NetShareEnum function.
An application cannot set the lpBuffer parameter to NULL and retrieve the required
buffer size from the lpBufferSize parameter. Instead, the application should allocate a
buffer of a reasonable size—16 kilobytes is typical—and use the value of lpBufferSize for
error detection.
Examples
For a code sample that illustrates an application-defined function that enumerates all
the resources on a network, see
Enumerating Network Resources.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetCloseEnum
WNetOpenEnum
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetConnectionA function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetGetConnection function retrieves the name of the network resource
associated with a local device.
Syntax
C++
DWORD WNetGetConnectionA(
);
Parameters
[in] lpLocalName
Pointer to a constant null-terminated string that specifies the name of the local device
to get the network name for.
[out] lpRemoteName
Pointer to a null-terminated string that receives the remote name used to make the
connection.
Pointer to a variable that specifies the size of the buffer pointed to by the
lpRemoteName parameter, in characters. If the function fails because the buffer is not
large enough, this parameter returns the required buffer size.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
If the network connection was made using the Microsoft LAN Manager network, and the
calling application is running in a different logon session than the application that made
the connection, a call to the
WNetGetConnection function for the associated local
device will fail. The function fails with ERROR_NOT_CONNECTED or
ERROR_CONNECTION_UNAVAIL. This is because a connection made using Microsoft
LAN Manager is visible only to applications running in the same logon session as the
application that made the connection. (To prevent the call to
WNetGetConnection from
failing it is not sufficient for the application to be running in the user account that
created the connection.)
Examples
For a code sample that illustrates how to use the
WNetGetConnection function to
retrieve the name of the network resource associated with a local device, see
Retrieving
the Connection Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetUser
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetConnectionW function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetGetConnection function retrieves the name of the network resource
associated with a local device.
Syntax
C++
DWORD WNetGetConnectionW(
);
Parameters
[in] lpLocalName
Pointer to a constant null-terminated string that specifies the name of the local device
to get the network name for.
[out] lpRemoteName
Pointer to a null-terminated string that receives the remote name used to make the
connection.
Pointer to a variable that specifies the size of the buffer pointed to by the
lpRemoteName parameter, in characters. If the function fails because the buffer is not
large enough, this parameter returns the required buffer size.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
If the network connection was made using the Microsoft LAN Manager network, and the
calling application is running in a different logon session than the application that made
the connection, a call to the
WNetGetConnection function for the associated local
device will fail. The function fails with ERROR_NOT_CONNECTED or
ERROR_CONNECTION_UNAVAIL. This is because a connection made using Microsoft
LAN Manager is visible only to applications running in the same logon session as the
application that made the connection. (To prevent the call to
WNetGetConnection from
failing it is not sufficient for the application to be running in the user account that
created the connection.)
Examples
For a code sample that illustrates how to use the
WNetGetConnection function to
retrieve the name of the network resource associated with a local device, see
Retrieving
the Connection Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetUser
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetLastErrorA function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetLastError function retrieves the most recent extended error code set by a
WNet function. The network provider reported this error code; it will not generally be
one of the errors included in the SDK header file WinError.h.
Syntax
C++
DWORD WNetGetLastErrorA(
);
Parameters
[out] lpError
Pointer to a variable that receives the error code reported by the network provider. The
error code is specific to the network provider.
[out] lpErrorBuf
Pointer to the buffer that receives the null-terminated string describing the error.
[in] nErrorBufSize
Size of the buffer pointed to by the lpErrorBuf parameter, in characters. If the buffer is
too small for the error string, the string is truncated but still null-terminated. A buffer of
at least 256 characters is recommended.
[out] lpNameBuf
Pointer to the buffer that receives the null-terminated string identifying the network
provider that raised the error.
[in] nNameBufSize
Size of the buffer pointed to by the lpNameBuf parameter, in characters. If the buffer is
too small for the error string, the string is truncated but still null-terminated.
Return value
If the function succeeds, and it obtains the last error that the network provider reported,
the return value is NO_ERROR.
Remarks
The
WNetGetLastError function retrieves errors that are specific to a network provider.
You can call
WNetGetLastError when a WNet function returns
ERROR_EXTENDED_ERROR.
Like the
GetLastError function,
WNetGetLastError returns extended error information,
which is maintained on a per-thread basis. Unlike GetLastError, the
WNetGetLastError
function can return a string for reporting errors that are not described by any existing
error code in WinError.h.
For more information about using an application-defined error handler that calls the
WNetGetLastError function, see
Retrieving Network Errors.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetLastErrorW function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetLastError function retrieves the most recent extended error code set by a
WNet function. The network provider reported this error code; it will not generally be
one of the errors included in the SDK header file WinError.h.
Syntax
C++
DWORD WNetGetLastErrorW(
);
Parameters
[out] lpError
Pointer to a variable that receives the error code reported by the network provider. The
error code is specific to the network provider.
[out] lpErrorBuf
Pointer to the buffer that receives the null-terminated string describing the error.
[in] nErrorBufSize
Size of the buffer pointed to by the lpErrorBuf parameter, in characters. If the buffer is
too small for the error string, the string is truncated but still null-terminated. A buffer of
at least 256 characters is recommended.
[out] lpNameBuf
Pointer to the buffer that receives the null-terminated string identifying the network
provider that raised the error.
[in] nNameBufSize
Size of the buffer pointed to by the lpNameBuf parameter, in characters. If the buffer is
too small for the error string, the string is truncated but still null-terminated.
Return value
If the function succeeds, and it obtains the last error that the network provider reported,
the return value is NO_ERROR.
Remarks
The
WNetGetLastError function retrieves errors that are specific to a network provider.
You can call
WNetGetLastError when a WNet function returns
ERROR_EXTENDED_ERROR.
Like the
GetLastError function,
WNetGetLastError returns extended error information,
which is maintained on a per-thread basis. Unlike GetLastError, the
WNetGetLastError
function can return a string for reporting errors that are not described by any existing
error code in WinError.h.
For more information about using an application-defined error handler that calls the
WNetGetLastError function, see
Retrieving Network Errors.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetNetworkInformationA function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetNetworkInformation function returns extended information about a
specific network provider whose name was returned by a previous network
enumeration.
Syntax
C++
DWORD WNetGetNetworkInformationA(
);
Parameters
[in] lpProvider
Pointer to a constant null-terminated string that contains the name of the network
provider for which information is required.
[out] lpNetInfoStruct
Pointer to a
NETINFOSTRUCT structure. The structure describes characteristics of the
network.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETINFOSTRUCT
NETRESOURCE
WNetEnumResource
WNetGetProviderName
WNetOpenEnum
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetNetworkInformationW
function (winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetNetworkInformation function returns extended information about a
specific network provider whose name was returned by a previous network
enumeration.
Syntax
C++
DWORD WNetGetNetworkInformationW(
);
Parameters
[in] lpProvider
Pointer to a constant null-terminated string that contains the name of the network
provider for which information is required.
[out] lpNetInfoStruct
Pointer to a
NETINFOSTRUCT structure. The structure describes characteristics of the
network.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETINFOSTRUCT
NETRESOURCE
WNetEnumResource
WNetGetProviderName
WNetOpenEnum
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetProviderNameA function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetProviderName function obtains the provider name for a specific type of
network.
Syntax
C++
DWORD WNetGetProviderNameA(
);
Parameters
[in] dwNetType
Network type that is unique to the network. If two networks claim the same type, the
function returns the name of the provider loaded first. Only the high word of the
network type is used. If a network reports a subtype in the low word, it is ignored.
You can find a complete list of network types in the header file Winnetwk.h.
[out] lpProviderName
Size of the buffer passed to the function, in characters. If the return value is
ERROR_MORE_DATA, lpBufferSize returns the buffer size required (in characters) to hold
the provider name.
Windows Me/98/95: The size of the buffer is in bytes, not characters. Also, the buffer
must be at least 1 byte long.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetResourceInformation
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetProviderNameW function
(winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetProviderName function obtains the provider name for a specific type of
network.
Syntax
C++
DWORD WNetGetProviderNameW(
);
Parameters
[in] dwNetType
Network type that is unique to the network. If two networks claim the same type, the
function returns the name of the provider loaded first. Only the high word of the
network type is used. If a network reports a subtype in the low word, it is ignored.
You can find a complete list of network types in the header file Winnetwk.h.
[out] lpProviderName
Size of the buffer passed to the function, in characters. If the return value is
ERROR_MORE_DATA, lpBufferSize returns the buffer size required (in characters) to hold
the provider name.
Windows Me/98/95: The size of the buffer is in bytes, not characters. Also, the buffer
must be at least 1 byte long.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetResourceInformation
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetResourceInformationA
function (winnetwk.h)
Article • 02/09/20233 minutes to read
Syntax
C++
DWORD WNetGetResourceInformationA(
);
Parameters
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the network resource for which
information is required.
The lpRemoteName member of the structure should specify the remote path name of
the resource, typically one typed in by a user. The lpProvider and dwType members
should also be filled in if known, because this operation can be memory intensive,
especially if you do not specify the dwType member. If you do not know the values for
these members, you should set them to NULL. All other members of the
NETRESOURCE
structure are ignored.
[out] lpBuffer
Pointer to the buffer to receive the result. On successful return, the first portion of the
buffer is a
NETRESOURCE structure representing that portion of the input resource path
that is accessed through the WNet functions, rather than through system functions
specific to the input resource type. (The remainder of the buffer contains the variable-
length strings to which the members of the
NETRESOURCE structure point.)
For example, if the input remote resource path is \server\share\dir1\dir2, then the
output
NETRESOURCE structure contains information about the resource \server\share.
The \dir1\dir2 portion of the path is accessed through the
file management functions.
The lpRemoteName, lpProvider, dwType, dwDisplayType, and dwUsage members of
NETRESOURCE are returned, with all other members set to NULL.
The lpRemoteName member is returned in the same syntax as the one returned from
an enumeration by the
WNetEnumResource function. This allows the caller to perform a
string comparison to determine whether the resource passed to
WNetGetResourceInformation is the same as the resource returned by a separate call
to
WNetEnumResource.
Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. The
buffer you allocate must be large enough to hold the
NETRESOURCE structure, plus the
strings to which its members point. If the buffer is too small for the result, this location
receives the required buffer size, and the function returns ERROR_MORE_DATA.
[out] lplpSystem
If the function returns successfully, this parameter points to a string in the output buffer
that specifies the part of the resource that is accessed through system functions. (This
applies only to functions specific to the resource type rather than the WNet functions.)
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetProviderName
WNetGetResourceParent
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetResourceInformationW
function (winnetwk.h)
Article • 02/09/20233 minutes to read
Syntax
C++
DWORD WNetGetResourceInformationW(
);
Parameters
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the network resource for which
information is required.
The lpRemoteName member of the structure should specify the remote path name of
the resource, typically one typed in by a user. The lpProvider and dwType members
should also be filled in if known, because this operation can be memory intensive,
especially if you do not specify the dwType member. If you do not know the values for
these members, you should set them to NULL. All other members of the
NETRESOURCE
structure are ignored.
[out] lpBuffer
Pointer to the buffer to receive the result. On successful return, the first portion of the
buffer is a
NETRESOURCE structure representing that portion of the input resource path
that is accessed through the WNet functions, rather than through system functions
specific to the input resource type. (The remainder of the buffer contains the variable-
length strings to which the members of the
NETRESOURCE structure point.)
For example, if the input remote resource path is \server\share\dir1\dir2, then the
output
NETRESOURCE structure contains information about the resource \server\share.
The \dir1\dir2 portion of the path is accessed through the
file management functions.
The lpRemoteName, lpProvider, dwType, dwDisplayType, and dwUsage members of
NETRESOURCE are returned, with all other members set to NULL.
The lpRemoteName member is returned in the same syntax as the one returned from
an enumeration by the
WNetEnumResource function. This allows the caller to perform a
string comparison to determine whether the resource passed to
WNetGetResourceInformation is the same as the resource returned by a separate call
to
WNetEnumResource.
Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. The
buffer you allocate must be large enough to hold the
NETRESOURCE structure, plus the
strings to which its members point. If the buffer is too small for the result, this location
receives the required buffer size, and the function returns ERROR_MORE_DATA.
[out] lplpSystem
If the function returns successfully, this parameter points to a string in the output buffer
that specifies the part of the resource that is accessed through system functions. (This
applies only to functions specific to the resource type rather than the WNet functions.)
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetProviderName
WNetGetResourceParent
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetResourceParentA function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetGetResourceParent function returns the parent of a network resource in the
network browse hierarchy. Browsing begins at the location of the specified network
resource.
Call the
WNetGetResourceInformation and
WNetGetResourceParent functions to move
up the network hierarchy. Call the
WNetOpenEnum function to move down the
hierarchy.
Syntax
C++
DWORD WNetGetResourceParentA(
);
Parameters
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the network resource for which the
parent name is required.
Member Meaning
[out] lpBuffer
The lpRemoteName member points to the remote name for the parent resource. This
name uses the same syntax as the one returned from an enumeration by the
WNetEnumResource function. The caller can perform a string comparison to determine
whether the
WNetGetResourceParent resource is the same as that returned by
WNetEnumResource. If the input resource has no parent on any of the networks, the
lpRemoteName member is returned as NULL.
Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. If
the buffer is too small to hold the result, this location receives the required buffer size,
and the function returns ERROR_MORE_DATA.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_ACCESS_DENIED The caller does not have access to the network resource.
Remarks
The
WNetGetResourceParent function is typically used in conjunction with the
WNetGetResourceInformation function to parse and interpret a network path typed in
by a user.
Unlike the
WNetGetResourceInformation function, if the resource includes a parent in
its syntax, the
WNetGetResourceParent function returns the parent, whether or not the
resource actually exists.
WNetGetResourceParent should typically be used only by
applications that display network resources to the user in a hierarchical fashion. The
Windows Explorer and the File Open dialog box are two well-known examples of this
type of application. Note that no assumptions should be made about the type of
resource that will be returned.
7 Note
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetProviderName
WNetGetResourceInformation
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetResourceParentW function
(winnetwk.h)
Article • 02/09/20233 minutes to read
The
WNetGetResourceParent function returns the parent of a network resource in the
network browse hierarchy. Browsing begins at the location of the specified network
resource.
Call the
WNetGetResourceInformation and
WNetGetResourceParent functions to move
up the network hierarchy. Call the
WNetOpenEnum function to move down the
hierarchy.
Syntax
C++
DWORD WNetGetResourceParentW(
);
Parameters
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the network resource for which the
parent name is required.
Member Meaning
[out] lpBuffer
The lpRemoteName member points to the remote name for the parent resource. This
name uses the same syntax as the one returned from an enumeration by the
WNetEnumResource function. The caller can perform a string comparison to determine
whether the
WNetGetResourceParent resource is the same as that returned by
WNetEnumResource. If the input resource has no parent on any of the networks, the
lpRemoteName member is returned as NULL.
Pointer to a location that, on entry, specifies the size of the lpBuffer buffer, in bytes. If
the buffer is too small to hold the result, this location receives the required buffer size,
and the function returns ERROR_MORE_DATA.
Return value
If the function succeeds, the return value is NO_ERROR.
ERROR_ACCESS_DENIED The caller does not have access to the network resource.
Remarks
The
WNetGetResourceParent function is typically used in conjunction with the
WNetGetResourceInformation function to parse and interpret a network path typed in
by a user.
Unlike the
WNetGetResourceInformation function, if the resource includes a parent in
its syntax, the
WNetGetResourceParent function returns the parent, whether or not the
resource actually exists.
WNetGetResourceParent should typically be used only by
applications that display network resources to the user in a hierarchical fashion. The
Windows Explorer and the File Open dialog box are two well-known examples of this
type of application. Note that no assumptions should be made about the type of
resource that will be returned.
7 Note
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetGetNetworkInformation
WNetGetProviderName
WNetGetResourceInformation
WNetGetUniversalName
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetUniversalNameA function
(winnetwk.h)
Article • 02/09/20236 minutes to read
The
WNetGetUniversalName function takes a drive-based path for a network resource
and returns an information structure that contains a more universal form of the name.
Syntax
C++
DWORD WNetGetUniversalNameA(
);
Parameters
[in] lpLocalPath
For example, if drive H has been mapped to a network drive share, and the network
resource of interest is a file named Sample.doc in the directory \Win32\Examples on that
share, the drive-based path is H:\Win32\Examples\Sample.doc.
[in] dwInfoLevel
The type of structure that the function stores in the buffer pointed to by the lpBuffer
parameter. This parameter can be one of the following values defined in the Winnetwk.h
header file.
Value Meaning
The
UNIVERSAL_NAME_INFO structure points to a Universal Naming Convention (UNC)
name string.
The
REMOTE_NAME_INFO structure points to a UNC name string and two additional
connection information strings. For more information, see the following Remarks
section.
[out] lpBuffer
A pointer to a buffer that receives the structure specified by the dwInfoLevel parameter.
A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the
lpBuffer parameter.
If the function succeeds, it sets the variable pointed to by lpBufferSize to the number of
bytes stored in the buffer. If the function fails because the buffer is too small, this
location receives the required buffer size, and the function returns ERROR_MORE_DATA.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
A universal form of a local drive-based path identifies a network resource in an
unambiguous, computer-independent manner. The name can then be passed to
processes on other computers, allowing those processes to obtain access to the
resource.
The
WNetGetUniversalName function currently supports one universal name form:
universal naming convention (UNC) names, which look like the following:
syntax
\\servername\sharename\path\file
Using the example from the preceding description of the lpLocalPath parameter, if the
shared network drive is on a server named COOLSERVER, and the share name is
HOTSHARE, the UNC name for the network resource whose drive-based name is
H:\Win32\Examples\Sample.doc would be the following:
syntax
\\coolserver\hotshare\win32\examples\sample.doc
The
UNIVERSAL_NAME_INFO structure contains a pointer to a UNC name string. The
REMOTE_NAME_INFO structure also contains a pointer to a UNC name string as well as
pointers to two other useful strings. For example, a process can pass the
REMOTE_NAME_INFO structure's lpszConnectionInfo member to the
WNetAddConnection2 function to connect a local device to the network resource. Then
the process can append the string pointed to by the lpszRemainingPath member to the
local device string. The resulting string can be passed to functions that require a drive-
based path.
The lpLocalPath parameter does not have to specify a path or resource that is already
present on a remote resource. For example, the lpLocalPath parameter could specify and
folder, a hierarchy of folders, or a file that does not currently exist. The
WNetGetUniversalName function returns a more universal form of the name in these
cases.
The size of the buffer pointed to by the lpBuffer parameter and specified in the
lpBufferSize parameter must be much larger than the size of the REMOTE_NAME_INFO
or UNIVERSAL_NAME_INFO structures. The buffer pointed to by the lpBuffer parameter
must be large enough to store the UNC strings pointed to by the members in the
REMOTE_NAME_INFO
or UNIVERSAL_NAME_INFO structures. If the buffer size is too
small, then the function fails with ERROR_MORE_DATA and the variable pointed to by
the lpBufferSize parameter indicates the required buffer size.
Examples
The following code sample illustrates how to use the
WNetGetUniversalName function
to retrieve the universal UNC name strings associated with drive-based path for a
network resource.
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
WCHAR Buffer[1024];
UNIVERSAL_NAME_INFO * unameinfo;
REMOTE_NAME_INFO *remotenameinfo;
//
//
if (dwRetVal == NO_ERROR) {
else {
//
//
if (dwRetVal == NO_ERROR) {
else {
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Determining the Location of a Share
REMOTE_NAME_INFO
UNIVERSAL_NAME_INFO
WNetAddConnection2
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetUniversalNameW function
(winnetwk.h)
Article • 02/09/20236 minutes to read
The
WNetGetUniversalName function takes a drive-based path for a network resource
and returns an information structure that contains a more universal form of the name.
Syntax
C++
DWORD WNetGetUniversalNameW(
);
Parameters
[in] lpLocalPath
For example, if drive H has been mapped to a network drive share, and the network
resource of interest is a file named Sample.doc in the directory \Win32\Examples on that
share, the drive-based path is H:\Win32\Examples\Sample.doc.
[in] dwInfoLevel
The type of structure that the function stores in the buffer pointed to by the lpBuffer
parameter. This parameter can be one of the following values defined in the Winnetwk.h
header file.
Value Meaning
The
UNIVERSAL_NAME_INFO structure points to a Universal Naming Convention (UNC)
name string.
The
REMOTE_NAME_INFO structure points to a UNC name string and two additional
connection information strings. For more information, see the following Remarks
section.
[out] lpBuffer
A pointer to a buffer that receives the structure specified by the dwInfoLevel parameter.
A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the
lpBuffer parameter.
If the function succeeds, it sets the variable pointed to by lpBufferSize to the number of
bytes stored in the buffer. If the function fails because the buffer is too small, this
location receives the required buffer size, and the function returns ERROR_MORE_DATA.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
A universal form of a local drive-based path identifies a network resource in an
unambiguous, computer-independent manner. The name can then be passed to
processes on other computers, allowing those processes to obtain access to the
resource.
The
WNetGetUniversalName function currently supports one universal name form:
universal naming convention (UNC) names, which look like the following:
syntax
\\servername\sharename\path\file
Using the example from the preceding description of the lpLocalPath parameter, if the
shared network drive is on a server named COOLSERVER, and the share name is
HOTSHARE, the UNC name for the network resource whose drive-based name is
H:\Win32\Examples\Sample.doc would be the following:
syntax
\\coolserver\hotshare\win32\examples\sample.doc
The
UNIVERSAL_NAME_INFO structure contains a pointer to a UNC name string. The
REMOTE_NAME_INFO structure also contains a pointer to a UNC name string as well as
pointers to two other useful strings. For example, a process can pass the
REMOTE_NAME_INFO structure's lpszConnectionInfo member to the
WNetAddConnection2 function to connect a local device to the network resource. Then
the process can append the string pointed to by the lpszRemainingPath member to the
local device string. The resulting string can be passed to functions that require a drive-
based path.
The lpLocalPath parameter does not have to specify a path or resource that is already
present on a remote resource. For example, the lpLocalPath parameter could specify and
folder, a hierarchy of folders, or a file that does not currently exist. The
WNetGetUniversalName function returns a more universal form of the name in these
cases.
The size of the buffer pointed to by the lpBuffer parameter and specified in the
lpBufferSize parameter must be much larger than the size of the REMOTE_NAME_INFO
or UNIVERSAL_NAME_INFO structures. The buffer pointed to by the lpBuffer parameter
must be large enough to store the UNC strings pointed to by the members in the
REMOTE_NAME_INFO
or UNIVERSAL_NAME_INFO structures. If the buffer size is too
small, then the function fails with ERROR_MORE_DATA and the variable pointed to by
the lpBufferSize parameter indicates the required buffer size.
Examples
The following code sample illustrates how to use the
WNetGetUniversalName function
to retrieve the universal UNC name strings associated with drive-based path for a
network resource.
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
WCHAR Buffer[1024];
UNIVERSAL_NAME_INFO * unameinfo;
REMOTE_NAME_INFO *remotenameinfo;
//
//
if (dwRetVal == NO_ERROR) {
else {
//
//
if (dwRetVal == NO_ERROR) {
else {
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Determining the Location of a Share
REMOTE_NAME_INFO
UNIVERSAL_NAME_INFO
WNetAddConnection2
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetUserA function (winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetUser function retrieves the current default user name, or the user name
used to establish a network connection.
Syntax
C++
DWORD WNetGetUserA(
);
Parameters
[in] lpName
A pointer to a constant null-terminated string that specifies either the name of a local
device that has been redirected to a network resource, or the remote name of a network
resource to which a connection has been made without redirecting a local device.
If this parameter is NULL or the empty string, the system returns the name of the
current user for the process.
[out] lpUserName
A pointer to a variable that specifies the size of the lpUserName buffer, in characters. If
the call fails because the buffer is not large enough, this variable contains the required
buffer size.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a
system error code, such as one of the following
values.
Remarks
The WNetGetUser function is not aware of shares on the Distributed File System (DFS).
If the name specified by the lpName parameter is a local device redirected to a DFS
share or a remote resource that represents a DFS share, the WNetGetUser function fails
with ERROR_NOT_CONNECTED.
Examples
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
WCHAR UserName[MAX_PATH];
if (argc != 2) {
wprintf
argv[0]);
exit(1);
//
//
if (dwRetVal == NO_ERROR) {
exit(0);
else {
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Retrieving the User Name
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetGetUserW function (winnetwk.h)
Article • 02/09/20232 minutes to read
The
WNetGetUser function retrieves the current default user name, or the user name
used to establish a network connection.
Syntax
C++
DWORD WNetGetUserW(
);
Parameters
[in] lpName
A pointer to a constant null-terminated string that specifies either the name of a local
device that has been redirected to a network resource, or the remote name of a network
resource to which a connection has been made without redirecting a local device.
If this parameter is NULL or the empty string, the system returns the name of the
current user for the process.
[out] lpUserName
A pointer to a variable that specifies the size of the lpUserName buffer, in characters. If
the call fails because the buffer is not large enough, this variable contains the required
buffer size.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a
system error code, such as one of the following
values.
Remarks
The WNetGetUser function is not aware of shares on the Distributed File System (DFS).
If the name specified by the lpName parameter is a local device redirected to a DFS
share or a remote resource that represents a DFS share, the WNetGetUser function fails
with ERROR_NOT_CONNECTED.
Examples
C++
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <Winnetwk.h>
DWORD dwRetVal;
WCHAR UserName[MAX_PATH];
if (argc != 2) {
wprintf
argv[0]);
exit(1);
//
//
if (dwRetVal == NO_ERROR) {
exit(0);
else {
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Retrieving the User Name
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetOpenEnumA function
(winnetwk.h)
Article • 02/09/20234 minutes to read
The
WNetOpenEnum function starts an enumeration of network resources or existing
connections. You can continue the enumeration by calling the
WNetEnumResource
function.
Syntax
C++
DWORD WNetOpenEnumA(
);
Parameters
[in] dwScope
Scope of the enumeration. This parameter can be one of the following values.
Value Meaning
[in] dwType
Resource types to be enumerated. This parameter can be a combination of the following
values.
Value Meaning
If a network provider cannot distinguish between print and disk resources, it can
enumerate all resources.
[in] dwUsage
Value Meaning
0 All resources.
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the container to enumerate. If the
dwScope parameter is not RESOURCE_GLOBALNET, this parameter must be NULL.
If this parameter is NULL, the root of the network is assumed. (The system organizes a
network as a hierarchy; the root is the topmost container in the network.)
[out] lphEnum
Return value
If the function succeeds, the return value is NO_ERROR.
The
WNetOpenEnum function is used to begin enumeration of the resources in a single
container. The following examples show the hierarchical structure of a Microsoft LAN
Manager network and a Novell NetWare network and identify the containers.
syntax
PAYFILES (disk)
LASERJET (print)
ANOTHERVOLUME (disk)
LASERJET (print)
Examples
For a code sample that illustrates an application-defined function that enumerates all
the resources on a network, see
Enumerating Network Resources.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetCloseEnum
WNetEnumResource
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetOpenEnumW function
(winnetwk.h)
Article • 02/09/20234 minutes to read
The
WNetOpenEnum function starts an enumeration of network resources or existing
connections. You can continue the enumeration by calling the
WNetEnumResource
function.
Syntax
C++
DWORD WNetOpenEnumW(
);
Parameters
[in] dwScope
Scope of the enumeration. This parameter can be one of the following values.
Value Meaning
[in] dwType
Resource types to be enumerated. This parameter can be a combination of the following
values.
Value Meaning
If a network provider cannot distinguish between print and disk resources, it can
enumerate all resources.
[in] dwUsage
Value Meaning
0 All resources.
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies the container to enumerate. If the
dwScope parameter is not RESOURCE_GLOBALNET, this parameter must be NULL.
If this parameter is NULL, the root of the network is assumed. (The system organizes a
network as a hierarchy; the root is the topmost container in the network.)
[out] lphEnum
Return value
If the function succeeds, the return value is NO_ERROR.
The
WNetOpenEnum function is used to begin enumeration of the resources in a single
container. The following examples show the hierarchical structure of a Microsoft LAN
Manager network and a Novell NetWare network and identify the containers.
syntax
PAYFILES (disk)
LASERJET (print)
ANOTHERVOLUME (disk)
LASERJET (print)
Examples
For a code sample that illustrates an application-defined function that enumerates all
the resources on a network, see
Enumerating Network Resources.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
NETRESOURCE
WNetCloseEnum
WNetEnumResource
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetRestoreConnectionW function
(winnetwk.h)
Article • 10/13/20212 minutes to read
Syntax
C++
DWORD WNetRestoreConnectionW(
);
Parameters
[in] hWnd
Handle to the parent window that the function uses to display the user interface (UI)
that prompts the user for a name and password when making the network connection.
If this parameter is NULL, there is no owner window.
[in] lpDevice
Pointer to a null-terminated Unicode string that specifies the local name of the drive to
connect to, such as "Z:". If this parameter is NULL, the function reconnects all persistent
drives stored in the registry for the current user.
Return value
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is a system error code, such as one of the following
values.
Remarks
The WNetRestoreConnectionW function is not supported on Windows Vista and later.
To call this function, first call the LoadLibrary function to load Mpr.dll. Then call the
GetProcAddress function to retrieve the address of the WNetRestoreConnectionW
function.
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
Windows
Networking (WNet) Overview
Windows
Networking Functions
WNetUseConnectionA function
(winnetwk.h)
Article • 02/09/20239 minutes to read
The
WNetUseConnection function makes a connection to a network resource. The
function can redirect a local device to a network resource.
The
WNetUseConnection function is similar to the
WNetAddConnection3 function. The
main difference is that
WNetUseConnection can automatically select an unused local
device to redirect to the network resource.
Syntax
C++
DWORD WNetUseConnectionA(
);
Parameters
[in] hwndOwner
Handle to a window that the provider of network resources can use as an owner window
for dialog boxes. Use this parameter if you set the CONNECT_INTERACTIVE value in the
dwFlags parameter.
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies details of the proposed connection.
The structure contains information about the network resource, the local device, and the
network resource provider.
You should set this member only if you know the network
provider you want to use. Otherwise, let the operating
system determine which provider the network name
maps to.
The
WNetUseConnection function ignores the other members of the
NETRESOURCE
structure. For more information, see the descriptions following for the dwFlags
parameter.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by lpUserID.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserId
Pointer to a constant null-terminated string that specifies a user name for making the
connection.
If lpUserID is NULL, the function uses the default user name. (The user context for the
process provides the default user name.)
The lpUserID parameter is specified when users want to connect to a network resource
for which they have been assigned a user name or account other than the default user
name or account.
[in] dwFlags
Set of bit flags describing the connection. This parameter can be any combination of the
following values.
Value Meaning
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_REDIRECT This flag forces the redirection of a local device when
making the connection.
If the lpLocalName member of
NETRESOURCE specifies a
local device to redirect, this flag has no effect, because
the operating system still attempts to redirect the
specified device. When the operating system
automatically chooses a local device, the dwType
member must not be equal to RESOURCETYPE_ANY.
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
[out] lpAccessName
Pointer to a buffer that receives system requests on the connection. This parameter can
be NULL.
Otherwise, the name copied into the buffer is that of a remote resource. If specified, this
buffer must be at least as large as the string pointed to by the lpRemoteName member.
Pointer to a variable that specifies the size of the lpAccessName buffer, in characters. If
the call fails because the buffer is not large enough, the function returns the required
buffer size in this location. For more information, see the descriptions of the
lpAccessName parameter and the ERROR_MORE_DATA error code in the Return Values
section.
[out] lpResult
Pointer to a variable that receives additional information about the connection. This
parameter can be the following value.
Value Meaning
CONNECT_LOCALDRIVE If this flag is set, the connection was made using a local
device redirection. If the lpAccessName parameter points
to a buffer, the local device name is copied to the buffer.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WnetCancelConnection
WNetUseConnectionW function
(winnetwk.h)
Article • 02/09/20239 minutes to read
The
WNetUseConnection function makes a connection to a network resource. The
function can redirect a local device to a network resource.
The
WNetUseConnection function is similar to the
WNetAddConnection3 function. The
main difference is that
WNetUseConnection can automatically select an unused local
device to redirect to the network resource.
Syntax
C++
DWORD WNetUseConnectionW(
);
Parameters
[in] hwndOwner
Handle to a window that the provider of network resources can use as an owner window
for dialog boxes. Use this parameter if you set the CONNECT_INTERACTIVE value in the
dwFlags parameter.
[in] lpNetResource
Pointer to a
NETRESOURCE structure that specifies details of the proposed connection.
The structure contains information about the network resource, the local device, and the
network resource provider.
You should set this member only if you know the network
provider you want to use. Otherwise, let the operating
system determine which provider the network name
maps to.
The
WNetUseConnection function ignores the other members of the
NETRESOURCE
structure. For more information, see the descriptions following for the dwFlags
parameter.
[in] lpPassword
If lpPassword is NULL, the function uses the current default password associated with
the user specified by lpUserID.
If lpPassword points to an empty string, the function does not use a password.
[in] lpUserId
Pointer to a constant null-terminated string that specifies a user name for making the
connection.
If lpUserID is NULL, the function uses the default user name. (The user context for the
process provides the default user name.)
The lpUserID parameter is specified when users want to connect to a network resource
for which they have been assigned a user name or account other than the default user
name or account.
[in] dwFlags
Set of bit flags describing the connection. This parameter can be any combination of the
following values.
Value Meaning
CONNECT_INTERACTIVE If this flag is set, the operating system may interact with
the user for authentication purposes.
CONNECT_PROMPT This flag instructs the system not to use any default
settings for user names or passwords without offering the
user the opportunity to supply an alternative. This flag is
ignored unless CONNECT_INTERACTIVE is also set.
CONNECT_REDIRECT This flag forces the redirection of a local device when
making the connection.
If the lpLocalName member of
NETRESOURCE specifies a
local device to redirect, this flag has no effect, because
the operating system still attempts to redirect the
specified device. When the operating system
automatically chooses a local device, the dwType
member must not be equal to RESOURCETYPE_ANY.
CONNECT_COMMANDLINE If this flag is set, the operating system prompts the user
for authentication using the command line instead of a
graphical user interface (GUI). This flag is ignored unless
CONNECT_INTERACTIVE is also set.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
CONNECT_CMD_SAVECRED If this flag is set, and the operating system prompts for a
credential, the credential should be saved by the
credential manager. If the credential manager is disabled
for the caller's logon session, or if the network provider
does not support saving credentials, this flag is ignored.
This flag is also ignored unless you set the
CONNECT_COMMANDLINE flag.
Windows 2000/NT and Windows Me/98/95: This value
is not supported.
[out] lpAccessName
Pointer to a buffer that receives system requests on the connection. This parameter can
be NULL.
Otherwise, the name copied into the buffer is that of a remote resource. If specified, this
buffer must be at least as large as the string pointed to by the lpRemoteName member.
Pointer to a variable that specifies the size of the lpAccessName buffer, in characters. If
the call fails because the buffer is not large enough, the function returns the required
buffer size in this location. For more information, see the descriptions of the
lpAccessName parameter and the ERROR_MORE_DATA error code in the Return Values
section.
[out] lpResult
Pointer to a variable that receives additional information about the connection. This
parameter can be the following value.
Value Meaning
CONNECT_LOCALDRIVE If this flag is set, the connection was made using a local
device redirection. If the lpAccessName parameter points
to a buffer, the local device name is copied to the buffer.
Return value
If the function succeeds, the return value is NO_ERROR.
Remarks
Windows Server 2003 and Windows XP: The WNet functions create and delete
network drive letters in the MS-DOS device namespace associated with a logon session
because MS-DOS devices are identified by AuthenticationID. (An AuthenticationID is the
locally unique identifier, or LUID, associated with a logon session.) This can affect
applications that call one of the WNet functions to create a network drive letter under
one user logon, but query for existing network drive letters under a different user logon.
An example of this situation could be when a user's second logon is created within a
logon session, for example, by calling the
CreateProcessAsUser function, and the second
logon runs an application that calls the
GetLogicalDrives function. GetLogicalDrives
does not return network drive letters created by a WNet function under the first logon.
Note that in the preceding example the first logon session still exists, and the example
could apply to any logon session, including a Terminal Services session. For more
information, see
Defining an MS-DOS Device Name.
7 Note
Requirements
Header winnetwk.h
Library Mpr.lib
DLL Mpr.dll
See also
WNetAddConnection2
WNetAddConnection3
WNetGetConnection
Windows
Networking (WNet) Overview
Windows
Networking Functions
WnetCancelConnection