Solved

Network Drives

Posted on 1998-08-28
10
159 Views
Last Modified: 2010-04-30
How do you map a network drive with VB, not using Shell() and "net use"? (no dos commands)
0
Comment
Question by:IsleOfView
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 2

Expert Comment

by:dabellei
ID: 1431678
Wich network are you using
0
 

Author Comment

by:IsleOfView
ID: 1431679
Microsoft Networking - I need to connect to a CD Server and to an NT File Server.  (I believe all are running WINS over TCP/IP)
0
 

Expert Comment

by:mskannan
ID: 1431680

I faced a few problems while mapping a network drive.
Suppose if i use net use to map a drive and assign a letter(say M) and if the user has already mapped any network drives for this letter, then this command automatically overwrites the drive letter and my end users are sometimes complaining about this feature.

Later, instead of mapping a drive and assigning a letter, I used to map the drive by its path. This is working fine.

\\Server1\foldername

You can also try this one.




0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 14

Expert Comment

by:waty
ID: 1431681
Here is complete code to map network drive in VB. I have to do that because, I map drives from a particular NT Server :

If you like this code, award me points.


Option Explicit
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long

Const WN_Success = &H0
Const WN_Not_Supported = &H1
Const WN_Net_Error = &H2
Const WN_Bad_Pointer = &H4
Const WN_Bad_NetName = &H32
Const WN_Bad_Password = &H6
Const WN_Bad_Localname = &H33
Const WN_Access_Denied = &H7
Const WN_Out_Of_Memory = &HB
Const WN_Already_Connected = &H34

'-- Error number and message
Public ErrorNum         As Long
Public ErrorMsg         As String

Public rc               As Long

Private Const ERROR_NO_CONNECTION = 8
Private Const ERROR_NO_DISCONNECT = 9

Public Sub Connect(sDrive As String, sService As String, Optional sPassword As String = "")
   
   On Error GoTo Err_Connect
   Me.ErrorNum = 0
   Me.ErrorMsg = ""
   rc = WNetAddConnection(sService & Chr(0), sPassword & Chr(0), sDrive & Chr(0))
   If rc <> 0 Then GoTo Err_Connect
   
   Exit Sub

Err_Connect:
   Me.ErrorNum = rc
   Me.ErrorMsg = WnetError(rc)

End Sub

Public Sub DisConnect(sDrive As String)
   
   On Error GoTo Err_DisConnect
   Me.ErrorNum = 0
   Me.ErrorMsg = ""
   rc = WNetCancelConnection(sDrive + Chr(0), 0)
   If rc <> 0 Then GoTo Err_DisConnect
   
   Exit Sub
Err_DisConnect:
   Me.ErrorNum = rc
   Me.ErrorMsg = WnetError(rc)

End Sub

Private Function WnetError(Errcode As Long) As String

   Select Case Errcode
      Case WN_Not_Supported:
         WnetError = "Function is not supported."
      Case WN_Out_Of_Memory:
         WnetError = "Out of Memory."
      Case WN_Net_Error:
         WnetError = "An error occurred on the network."
      Case WN_Bad_Pointer:
         WnetError = "The Pointer was Invalid."
      Case WN_Bad_NetName:
         WnetError = "Invalid Network Resource Name."
      Case WN_Bad_Password:
         WnetError = "The Password was Invalid."
      Case WN_Bad_Localname:
         WnetError = "The local device name was invalid."
      Case WN_Access_Denied:
         WnetError = "A security violation occurred."
      Case WN_Already_Connected:
         WnetError = "The local device was connected to a remote resource."
      Case Else:
         WnetError = "Unrecognized Error " + str(Errcode) + "."
   End Select

End Function


0
 

Author Comment

by:IsleOfView
ID: 1431682
In response to waty's answer--I tried that code, but when I print the debugging info, I get an unrecognized error "1326".  Any ideas?
0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1431683
There are a few Microsoft Articles on dealing with this one.  These may help, the numbers are:
     Q173011
     Q138905
     Q138904
     

I have some code at the office.  If some of these look like they will help, just let me know.

Later
0
 
LVL 14

Expert Comment

by:waty
ID: 1431684
What do you try to connect, I use those API to connect NT drives, and Unix drives.

Could you explain a little more
0
 

Author Comment

by:IsleOfView
ID: 1431685
Thanks to mkmccreary, Q173011 detailed the answer to my question perfectly.
0
 
LVL 2

Accepted Solution

by:
mkmccreary earned 40 total points
ID: 1431686
Glad it helped out.

Later,
Martin
0
 
LVL 6

Expert Comment

by:alamo
ID: 1431687
?!?
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question