
WNetAddConnection2 API Call ????????
Try this code.....
******** Global.bas******
Option Explicit
Public Const ERROR_INVALID_FUNCTION = 1&
Public Const ERROR_ACCESS_DENIED = 5&
Public Const ERROR_OUTOFMEMORY = 14&
Public Const ERROR_ALREADY_CONNECTED = 52&
Public Const ERROR_BAD_NETPATH = 53&
Public Const ERROR_UNSHARED_RESOURCE = 67&
Public Const ERROR_BAD_NET_NAME = 67&
Public Const ERROR_ALREADY_ASSIGNED = 85&
Public Const ERROR_INVALID_PASSWORD = 86&
Public Const ERROR_BUFFER_OVERFLOW = 111&
Public Const ERROR_BAD_PATHNAME = 161&
Public Const ERROR_ALREADY_EXISTS = 183&
Public Const ERROR_NO_RESOURCE_NAME = 487&
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_BAD_PROVIDER = 1204&
Public Const ERROR_BAD_PROFILE = 1206&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_INVALID_PASSWORDNAME = 1216&
Public Const ERROR_INTERNAL_ERROR = 1359&
Public Const ERROR_INVALID_PRINTER_NAME = 1801&
Public Const ERROR_BAD_USERNAME = 2202&
Public Const ERROR_LOCAL_DRIVE = 2250&
Public Const ERROR_BUSY = 170&
Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCETYPE_PRINT = &H2
Public Const RESOURCETYPE_UNKNOWN = &HFFFF
Public Const CONNECT_UPDATE_PROFILE = &H1
Public Type NETRESOURCE
lngScope As Long
lngType As Long
lngDisplayType As Long
lngUsage As Long
strLocalName As String
strRemoteName As String
strComment As String
strProvider As String
End Type
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias
"WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As
String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
********Form1*******
Private Sub Command1_Click()
Dim nrType As NETRESOURCE 'variable to hold the NETRESOURCE values
Dim lngRetVal As Long 'variable to hold the return
value from the function
Dim strPassword As String 'variable to hold the password
Dim strUserName As String 'variable to hold the user name
Dim lngConnect As Long 'variable to hold the connection
type
nrType.lngType = RESOURCETYPE_DISK 'This is the type of connection
nrType.strLocalName = "O:" 'This is the local resource you want to
use
nrType.strRemoteName = "\\<server>\<share>" 'The remote resource to
connect to
nrType.strProvider = "" 'Leave this NULL or empty to force the system
to choose
strPassword = "" 'If blank, no password is used
strUserName = "" 'If blank, the current username is used
lngConnect = CONNECT_UPDATE_PROFILE 'This makes a persistent connection
_
Use a value of
0 for non-persistent connections
lngRetVal = WNetAddConnection2(nrType, strPassword, strUserName,
lngConnect)
MsgBox lngRetVal
End Sub
The function returns a value of 0 (or ERROR_SUCCESS) if the connection
attempt is successful. If it isn't, it returns one of the error codes
declared in the global.bas module. You can test your return value and
take actions accordingly. Hope this helps. A good source for using the
Windows Network API functions is Daniel Appleman's Visual Basic Win32 API
for VB 5.0 -- note the 4.0 version does NOT include the network API calls.
cdf
Quote:
> Does anyone know how to use this API? I don't know what to use as some
> of the parameters.
> Thanks,
> Brian Dourty