网站首页  词典首页

请输入您要查询的函数:

 

术语 wnetuseconnection
释义 WNetUseConnection
语法:
C++
DWORD WNetUseConnection(
__in HWND hwndOwner,
__in LPNETRESOURCE lpNetResource,
__in LPCTSTR lpPassword,
__in LPCTSTR lpUserID,
__in DWORD dwFlags,
__out LPTSTR lpAccessName,
__inout LPDWORD lpBufferSize,
__out LPDWORD lpResult
);
WNetUseConnection功能
该WNetUseConnection函数将连接到网络资源。该函数可以重定向本地设备到网络资源。
该WNetUseConnection功能类似于WNetAddConnection3功能。主要的区别是WNetUseConnection可以自动选择一个未使用本地设备来重定向到网络资源。
参数
hwndOwner [in]
句柄窗口,网络资源的提供者可以使用一个对话框的所有者窗口。使用这个参数如果设置在dwFlags参数CONNECT_INTERACTIVE值。
lpNetResource [in]
指针NETRESOURCE结构,指定拟议连接的详细信息。该结构包含有关网络资源的信息,本地设备和网络资源提供商。
您必须指定的NETRESOURCE结构以下成员。
MemberMeaning
dwTypeSpecifies资源的类型,以便连接。
这是最有效的指定在该会员的资源类型,如RESOURCETYPE_DISK或RESOURCETYPE_PRINT。但是,如果lpLocalName成员是NULL,或者如果它指向一个空字符串CONNECT_REDIRECT没有设置,却提示可以RESOURCETYPE_ANY。
此方法只有在函数不会自动选择一个设备来重定向到网络资源。
虽然这个成员是必需的,它的信息可能被忽略的网络服务供应商。
lpLocalNamePointer以NULL结尾的字符串,它指定了一个本地设备名被重定向,例如“传真:”或“中将”lpt1。该字符串被视为一个不区分大小写的方式。
如果字符串为空,或者lpLocalName为NULL,连接到网络的情况下发生重定向。
如果CONNECT_REDIRECT值设置在dwFlags参数,或者如果网络需要一个重定向的本地设备,功能选择一个本地设备,重新调整和回报的lpAccessName参数设备的名称。
lpRemoteNamePointer以NULL结尾的字符串,它指定了网络资源的连接。该字符串可达MAX_PATH字符的长度,它必须遵循网络提供商的命名约定。
lpProviderPointer以NULL结尾的字符串,指定供应商的网络连接。如果lpProvider是NULL,或者如果它指向一个空字符串解析字符串,操作系统尝试确定正确的供应商指出,由lpRemoteName成员。
如果这个成员不是NULL,操作系统尝试建立连接只名为网络提供商。
您应该设置这个成员仅当您知道您的网络提供商要使用。否则,让操作系统确定供应商网络的名称映射到。
该WNetUseConnection函数忽略了NETRESOURCE结构的其他成员。有关详细信息,请参阅下面的dwFlags参数说明。
lpPassword [in]
指针常量NULL结尾的字符串,指定一个密码被用于制造网络连接。
如果lpPassword为NULL,则函数使用当前默认的密码与lpUserID指定的用户关联。
如果lpPassword指向一个空字符串,该函数不使用密码。
如果连接失败,因为一个无效的密码和CONNECT_INTERACTIVE值在dwFlags参数设置,函数显示一个对话框,要求用户输入密码。
lpUserID [in]
指针常量NULL结尾的字符串,用于指定建立连接的用户名。
如果lpUserID为NULL,则函数使用默认的用户名。 (在这个进程的用户上下文提供了默认用户名。)
该lpUserID参数指定当用户想连接到网络资源,他们被分配一个用户名或帐户比默认的用户名或账户。
用户名字符串都代表一个安全上下文。这可能是特定于网络提供商。
dwFlags [in]
位集描述数据库连接的标志。此参数可以是任何下列值的组合。
ValueMeaning
CONNECT_INTERACTIVEIf设置此标志,操作系统可能会互动的用户进行身份验证。
CONNECT_PROMPTThis标志指示系统不使用情况下为用户提供的机会,提供一个可供选择的用户名或密码任何默认设置。这个标志被忽略,除非CONNECT_INTERACTIVE也设置。
CONNECT_REDIRECTThis旗部队的地方时,连接设备重定向。
如果NETRESOURCE lpLocalName成员指定本地设备重定向,这个标志没有任何效果,因为操作系统仍然试图重定向指定的设备。当操作系统自动选择本地设备,却提示成员必须不等于RESOURCETYPE_ANY。
如果此标志没有设置,本地设备自动重定向选择了只有在网络要求本地设备被重定向。
Windows XP的:当系统自动分配网络驱动器字母,字母Z开头指派:,则Y:,并结束与C:。这将减少每次登录(如网络驱动器号)和全球驱动器号(如磁盘驱动器)驱动器号相撞。请注意,以前的版本中分配驱动器号开始的C:和结束与Z:。
CONNECT_UPDATE_PROFILEThis标志指示操作系统存储网络资源的连接。
如果此位标志设置,操作系统会自动尝试恢复连接时,用户登录。该系统还记得成功的连接重定向本地设备。它不记得连接不成功或deviceless连接。 (阿deviceless连接时发生lpLocalName为NULL或当它指向一个空字符串。)
如果此位标志清晰,操作系统不会自动恢复在登录连接。
CONNECT_COMMANDLINEIf这标志设置,操作系统会提示使用命令行,而不是一个图形用户界面(GUI)认证的用户。这个标志被忽略,除非CONNECT_INTERACTIVE也设置。
的Windows 2000/NT和Windows 95/98:此值不支持。
CONNECT_CMD_SAVECREDIf设置此标志,和操作系统的一个凭据提示,凭据应当由凭据经理保存。如果凭据经理是调用者的登录会话,或者如果网络运营商不支持保存凭据残疾人,此标志将被忽略。这个标志也被忽略,除非您设置CONNECT_COMMANDLINE标志。
的Windows 2000/NT和Windows 95/98:此值不支持。
lpAccessName [out]
指针指向一个缓冲区,接收系统的连接请求。此参数可以为NULL。
如果该参数指定,以及NETRESOURCE结构lpLocalName成员指定本地设备,此缓冲区接收本地设备名。如果lpLocalName不指定设备和网络需要本地设备重定向,或者如果CONNECT_REDIRECT值设置,此缓冲区接收重定向的本地设备名。
否则,名称复制到缓冲区是,远程资源。如果指定,此缓冲区必须至少一样大串指出的lpRemoteName成员。
lpBufferSize [ in , out ]
Pointer to a variable that specifies the size of the lpAccessName buffer, in characters.如果调用失败,因为缓冲区不够大,则函数返回在此位置所需的缓冲区大小。有关更多信息,见lpAccessName参数和返回值中的第ERROR_MORE_DATA错误代码的说明。
lpResult [out]
指针变量,接收有关该连接的其他信息。此参数可以是以下值。
ValueMeaning
CONNECT_LOCALDRIVEIf设置此标志,连接了使用本地设备重定向。如果lpAccessName参数指向一个缓冲区,本地设备名被复制到缓冲区。
返回值
如果函数成功,返回值为NO_ERROR。
如果函数失败,返回值是一个系统错误代码,如下列值之一。
返回codeDescription
ERROR_ACCESS_DENIEDThe调用方不具有访问网络资源。
ERROR_ALREADY_ASSIGNEDThe本地设备的lpLocalName成员中指定已经连接到网络资源。
ERROR_BAD_DEVICEThe值lpLocalName指定无效。
ERROR_BAD_NET_NAMEThe价值的lpRemoteName成员中指定的是不能接受的任何网络资源提供者,因为该资源的名称是无效的,或者因为命名的资源无法找到。
ERROR_BAD_PROVIDERThe价值的lpProvider成员中指定不符合任何供应商。
ERROR_CANCELLEDThe企图使连接被取消通过一个对话框,从网络资源供应商,或由一个所谓的资源由用户。
ERROR_EXTENDED_ERRORA网络特定的错误。要获取该错误的描述,调用WNetGetLastError功能。
ERROR_INVALID_ADDRESSThe来电通过一个指针不能被访问的缓冲区。
ERROR_INVALID_PARAMETERThis错误是下列条件之一的结果:
该lpRemoteName成员为NULL。此外,lpAccessName不是NULL,但lpBufferSize是NULL或者为零点。
该却提示成员既不是RESOURCETYPE_DISK也不RESOURCETYPE_PRINT。此外,无论CONNECT_REDIRECT载于dwFlags和lpLocalName是NULL,或连接到网络,需要一个本地设备重定向。
ERROR_INVALID_PASSWORDThe指定的密码无效,CONNECT_INTERACTIVE未设置标志。
ERROR_MORE_DATAThe lpAccessName缓冲区太小。
如果本地设备被重定向,缓冲区必须足够大,以包含本地设备名。否则,缓冲区必须足够大,以包含任一字符串指向lpRemoteName,或可连接资源的别名指向lpRemoteName名称。如果此错误返回,则没有连接已作出。
ERROR_NO_MORE_ITEMSThe操作系统不能自动选择本地重定向,因为所有的有效的本地设备在使用。
ERROR_NO_NET_OR_BAD_PATHThe操作无法完成,或者是因为网络组件没有启动,或因为指定的资源名称不承认。
ERROR_NO_NETWORKThe网络不可用。
备注
Windows Server 2003和Windows XP中:在WNet函数创建和删除网络驱动器的MS字母- DOS设备命名与登录会话,因为MS - DOS设备是由AuthenticationID确定相关。 (一个AuthenticationID是当地唯一的标识符,或的LUID,与登录会话相关联。)这可能会影响应用程序的WNet函数调用来创建下一个用户登录网络驱动器号,但现有的网络驱动器字母查询下不同的用户登录。这种情况的一个例子是,当用户的第二个登录,在登录会话中创建,例如,通过调用运行CreateProcessAsUser函数,第二个登录的应用程序调用GetLogicalDrives函数。 GetLogicalDrives不会返回网络驱动器由一个WNet函数下创建首次登录字母。请注意,在前面的例子中第一个登录会话仍然存在,而且例子可以适用于任何登录会话,包括终端服务会话。有关更多信息,请参见定义一个MS - DOS设备名。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinnetwk.h
LibraryMpr.lib
DLLMpr.dll
Unicode和ANSI namesWNetUseConnectionW(Unicode)和WNetUseConnectionA(ANSI)的
参见
Windows网络(WNet)概述
Windows网络函数
WNetAddConnection2
WNetAddConnection3
WnetCancelConnection
WNetGetConnection
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月6日
==英文原文==WNetUseConnection Function
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 WNetUseConnection(
__in HWND hwndOwner,
__in LPNETRESOURCE lpNetResource,
__in LPCTSTR lpPassword,
__in LPCTSTR lpUserID,
__in DWORD dwFlags,
__out LPTSTR lpAccessName,
__inout LPDWORD lpBufferSize,
__out LPDWORD lpResult
);
Parameters
hwndOwner [in]
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.
lpNetResource [in]
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 must specify the following members of the NETRESOURCE structure.
MemberMeaning
dwTypeSpecifies the type of resource to connect to.
It is most efficient to specify a resource type in this member, such as RESOURCETYPE_DISK or RESOURCETYPE_PRINT. However, if the lpLocalName member is NULL, or if it points to an empty string and CONNECT_REDIRECT is not set, dwType can be RESOURCETYPE_ANY.
This method works only if the function does not automatically choose a device to redirect to the network resource.
Although this member is required, its information may be ignored by the network service provider.
lpLocalNamePointer to a 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 empty, or if lpLocalName is NULL, a connection to the network occurs without redirection.
If the CONNECT_REDIRECT value is set in the dwFlags parameter, or if the network requires a redirected local device, the function chooses a local device to redirect and returns the name of the device in the lpAccessName parameter.
lpRemoteNamePointer to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH characters in length, and it must follow the network provider's naming conventions.
lpProviderPointer to a null-terminated string that specifies the network provider to connect to. If lpProvider is NULL, or if it points to an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by the lpRemoteName member.
If this member is not NULL, the operating system attempts to make a connection only to the named network 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.
lpPassword [in]
Pointer to a constant null-terminated string that specifies a password to be used in making the network connection.
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.
If the connection fails because of an invalid password and the CONNECT_INTERACTIVE value is set in the dwFlags parameter, the function displays a dialog box asking the user to type the password.
lpUserID [in]
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.
The user-name string represents a security context . It may be specific to a network provider.
dwFlags [in]
Set of bit flags describing the connection. This parameter can be any combination of the following values.
ValueMeaning
CONNECT_INTERACTIVEIf this flag is set, the operating system may interact with the user for authentication purposes.
CONNECT_PROMPTThis 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_REDIRECTThis 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.
If this flag is not set, a local device is automatically chosen for redirection only if the network requires a local device to be redirected.
Windows XP: When the system automatically assigns network drive letters, letters are assigned beginning with Z:, then Y:, and ending with C:. This reduces collision between per-logon drive letters (such as network drive letters) and global drive letters (such as disk drives). Note that previous releases assigned drive letters beginning with C: and ending with Z:.
CONNECT_UPDATE_PROFILEThis flag instructs the operating system to store the network resource connection.
If this bit flag is set, the operating system automatically attempts to restore the connection when the user logs on. The system remembers only successful connections that redirect local devices. It does not remember connections that are unsuccessful or deviceless connections. (A deviceless connection occurs when lpLocalName is NULL or when it points to an empty string.)
If this bit flag is clear, the operating system does not automatically restore the connection at logon.
CONNECT_COMMANDLINEIf 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_SAVECREDIf 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.

lpAccessName [out]
Pointer to a buffer that receives system requests on the connection. This parameter can be NULL.
If this parameter is specified, and the lpLocalName member of the NETRESOURCE structure specifies a local device, this buffer receives the local device name. If lpLocalName does not specify a device and the network requires a local device redirection, or if the CONNECT_REDIRECT value is set, this buffer receives the name of the redirected local device.
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.
lpBufferSize [in, out]
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.
lpResult [out]
Pointer to a variable that receives additional information about the connection. This parameter can be the following value.
ValueMeaning
CONNECT_LOCALDRIVEIf 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.
If the function fails, the return value is a system error code , such as one of the following values.
Return codeDescription
ERROR_ACCESS_DENIEDThe caller does not have access to the network resource.
ERROR_ALREADY_ASSIGNEDThe local device specified by the lpLocalName member is already connected to a network resource.
ERROR_BAD_DEVICEThe value specified by lpLocalName is invalid.
ERROR_BAD_NET_NAMEThe value specified by the lpRemoteName member is not acceptable to any network resource provider because the resource name is invalid, or because the named resource cannot be located.
ERROR_BAD_PROVIDERThe value specified by the lpProvider member does not match any provider.
ERROR_CANCELLEDThe attempt to make the connection was canceled by the user through a dialog box from one of the network resource providers, or by a called resource.
ERROR_EXTENDED_ERRORA network-specific error occurred. To obtain a description of the error, call the WNetGetLastError function.
ERROR_INVALID_ADDRESSThe caller passed in a pointer to a buffer that could not be accessed.
ERROR_INVALID_PARAMETERThis error is a result of one of the following conditions:
The lpRemoteName member is NULL. In addition, lpAccessName is not NULL, but lpBufferSize is either NULL or points to zero.
The dwType member is neither RESOURCETYPE_DISK nor RESOURCETYPE_PRINT. In addition, either CONNECT_REDIRECT is set in dwFlags and lpLocalName is NULL, or the connection is to a network that requires the redirecting of a local device.
ERROR_INVALID_PASSWORDThe specified password is invalid and the CONNECT_INTERACTIVE flag is not set.
ERROR_MORE_DATAThe lpAccessName buffer is too small.
If a local device is redirected, the buffer needs to be large enough to contain the local device name. Otherwise, the buffer needs to be large enough to contain either the string pointed to by lpRemoteName, or the name of the connectable resource whose alias is pointed to by lpRemoteName. If this error is returned, then no connection has been made.
ERROR_NO_MORE_ITEMSThe operating system cannot automatically choose a local redirection because all the valid local devices are in use.
ERROR_NO_NET_OR_BAD_PATHThe operation could not be completed, either because a network component is not started, or because the specified resource name is not recognized.
ERROR_NO_NETWORKThe network is unavailable.

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 .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinnetwk.h
LibraryMpr.lib
DLLMpr.dll
Unicode and ANSI namesWNetUseConnectionW (Unicode) and WNetUseConnectionA (ANSI)
See Also
Windows Networking (WNet) Overview
Windows Networking Functions
WNetAddConnection2
WNetAddConnection3
WnetCancelConnection
WNetGetConnection
Send comments about this topic to Microsoft
Build date: 8/6/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa385482(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:22:34