Solved

Network Drives

Posted on 1998-08-28
10
156 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now