Solved

How Do You Map Network Drives in VB?

Posted on 1998-08-20
3
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 109
How does CurrentUser work? 10 42
Access Object Property from VBA Module in Excel 2010 2 39
Error with a code discussed on this page 5 39
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

749 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