Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help connecting to network resources 1

Status
Not open for further replies.

jancheta

Programmer
Aug 30, 2002
51
US
I need to connect to a network resource "\\servername\sharename" but the thing is that I need to provide a username for the resource since the current user logged on to the machine does not have the proper access domain rights.

I came across an API (please see below) however I can only provide a password which makes me think that windows defaults to the user login name as the default. Any ideas?

--- CODE ---
Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" _
(ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long

Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" _
(ByVal lpszName As String, ByVal bForce As Long) As Long

Const WN_SUCCESS = 0 ' The function was successful.
Const WN_NET_ERROR = 2 ' An error occurred on the network.
Const WN_BAD_PASSWORD = 6 ' The password was invalid.

------------
 
I found a solution to this problem. If you researched on this, thx for your time. I checked the WIN32API.TXT and found:

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

where the second and third parameters passed are the username and password.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top