How to Connect to a Network Drive by Using WNetAddConnectionLast reviewed: December 18, 1996Article ID: Q141757 |
The information in this article applies to:
SUMMARYWindows version 3.1 provides a new API Call, WNetAddConnection, which redirects a local device to a shared resource or network server. WNetAddConnection requires the name of the local device, the name of the network resource, and the password necessary to use that resource. This article explains in detail the arguments and potential error messages for the Windows version 3.1 WNetAddConnection function call.
MORE INFORMATIONTo use WNetAddConnection within a Visual Basic application, declare the WNetAddConnection function in the General Declarations Section of your code window. (In Visual Basic version 1.0 you can also put the declaration in the Global Module.) Declare the function as follows entering the entire Declare statement on one, single line:
Public Declare Function WnetAddConnection% Lib "user" (ByVal lpszNetPath As Any, ByVal lpszPassword As Any, ByVal lpszLocalName As Any)Here are the definitions for the formal parameters:
Formal Parameter Definition ----------------------------------------------------------------------- lpszNetPath Points to a null-terminated string specifying the shared device or remote server. lpszPassword Points to a null-terminated string specifying the network password for the given device or server. lpszLocalName Points to a null-terminated string specifying the local drive or device to be redirected. All lpszLocalName strings (such as LPT1) are case independent. Only the drive names A through Z and device names LPT1 through LPT3 are used.Below are the possible return values as defined on page 990 of the Microsoft Windows version 3.1 Programmer's Reference:
Value (Hex Value) Meaning ----------------------------------------------------------------------- WN_SUCCESS (&H0) Function was successful. WN_NOT_SUPPORTED (&H1) Function was not supported. WN_OUT_OF_MEMORY (&HB) System was out of memory. WN_NET_ERROR (&H2) An error occurred on the network. WN_BAD_POINTER (&H4) Pointer was invalid. WN_BAD_NETNAME (&H32) Network resource name was invalid. WN_BAD_LOCALNAME (&H33) Local device name was invalid. WN_BAD_PASSWORD (&H6) Password was invalid. WN_ACCESS_DENIED (&H7) A security violation occurred. WN_ALREADY_CONNECTED (&H34) Local device was already connected to a remote resource.Below is an example of how to redirect a local device to a network resource:
REFERENCESMSDN/VB Starter Kit, (contained with the Professional and Enterprise versions of Visual Basic 4.0), Product Documentation, SDKs, "Windows 3.1 SDK," Programmers Reference Volume 2, and the WIN31API.HLP file (also shipped with the Microsoft Visual Basic version 2.0, 3.0 Professional Version).
|
Additional reference words: 1.00 2.00 4.00 vb4win vb416
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |