Solved

How Do You Map Network Drives in VB?

Posted on 1998-08-20
3
196 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now