Solved

How Do You Map Network Drives in VB?

Posted on 1998-08-20
3
198 Views
Last Modified: 2010-04-30
How do you map and disconnect network drives in VB?

The following code doesn't seem to work:

#If Win32 Then
     Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As Long
     Declare Function WNetDisconnectDialog Lib "mpr.dll" (ByVal hWnd As Long, ByVal dwType As Long) As Long
#End If
 
Private Sub netdrivebutton_Click(Index As Integer)
     Dim i As Long
     Select Case Index
     Case 0  'Map To is Selected
         #If Win32 Then
             i = WNetConnectionDialog(Me.hWnd, RESOURCETYPE_DISK)
             If i <> 0 And i <> -1 And i <> 1223 Then
                 MsgBox "Error: " & i, 48, 1
             End If
         #End If
     Case 1  'Disconnect is Selected
         #If Win32 Then
             i = WNetDisconnectDialog(Me.hWnd, RESOURCETYPE_DISK)
         #End If
     End Select
End Sub
0
Comment
Question by:darren100
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
KEWL earned 10 total points
ID: 1430086
Sub MapDrive(Drv as string, Tgt as string)
shell ("NET USE " & drv & " " & tgt,0
End sub

Sub UnMap(Drv as string)
shell ("NET USE " & drv & " /delete"),0
end sub

These subs use the dos program NET that comes with w95/98.
it isnt very technical but it gets the job done
0
 
LVL 14

Expert Comment

by:waty
ID: 1430087
I have given you complete VB code in the following question :

http://www.experts-exchange.com/topics/comp/lang/visualbasic/Q.10073988

It uses API, no shell to extern app and works very well.
0
 
LVL 1

Expert Comment

by:KEWL
ID: 1430088
although i want the points, waty's API would be a better choice
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending a email via excel using vba 6 82
Prevent checkbox click event occur while editing it in vb6 8 44
Hide vba in gp 7 94
Send outlook email from VBS Script 2 29
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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