Accessing a remote network drive


I have a vb6 appl. that will run at different sites.  I will be using a central server located at one of the sites.  I will have crystal reports and other files at this site that I will need to access or copy from any of the sites.

I am using the crystal viewer and would like to open reports using the following:
Private Const str As String = "\\IP ADDR\share\folder\"
Set app = New CRAXDRT.Application
Set rpt = app.OpenReport(str & "Report1.rpt", 1)

I need to include the user login info with the IP addr and I don't want to map the drive with a letter.  What is the most efficent way to do this in my code?

Also, what's the best way to copy files over to the local machine?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Hi villny123,

> I need to include the user login info with the IP addr
Sorry, I don't follow what you mean.  What user login info are you talking about and what's the connection to the IP addr?

> what's the best way to copy files over to the local machine
If the files are being copied on a local network, then a normal copy is fine.  If instead they're being copied across a WAN, then I recommend using either ftp or http.

villny123Author Commented:
By the login I meant:  At one of the remote sites, I mapped a network drive to the server and in addition to using the ip addr, I also had to login with a user name.  I am assuming that I need to duplicate this in my code.
Here is a simple example. Paste this onto a form with 2 command buttons. Be sure to edit the UNC path,Username &  Password. This will connect you to the share without having a drive mapped.

Private 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
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long

   dwScope As Long
   dwType As Long
   dwDisplayType As Long
   dwUsage As Long
   lpLocalName As String
   lpRemoteName As String
   lpComment As String
   lpProvider As String
End Type

Private Sub Command1_Click()
Dim l As Long
With nr
    .lpLocalName = ""
    .lpRemoteName = "\\\MyShare\Somefolder" ' unc to access
    .lpProvider = ""
End With

' pass the username & password
l = WNetAddConnection2(nr, "Mypassword", "MyUsername", 0)

' do a filecopy here if you wish
'FileCopy "C:\Myfile.txt", "\\\MyShare\Somefolder\MyFile.txt"

End Sub

Private Sub Command2_Click()
' close connection
Dim l As Long
l = WNetCancelConnection2("\\\MyShare\Somefolder", 0, True)
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
villny123Author Commented:
I tried your solution and it worked... thanks a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.