Search Tools Links Login

Connect To and Disconnect From Network Drive(s)

Posted: 2002-06-01
By: ArchiveBot
Viewed: 70

Filed Under:

VB6 Code Cache

No attachments for this post


Being an NT network administrator and software engineer sure has its advantages.
Visual Basic 4.0 has afforded me the opportunity to create useful apps that
greatly reduce the amount of time it takes to perform those tasks that many of us
perform often. This little app simply uses the Windows 32 API (Win95 or NT 4.0 only)
to open the network resource browse list. You can map network resources or disconnect
from network resources.
Enjoy the code! We've been using it for months in several VB apps on our network
and it works GREAT!

Original Author: Keith Keller

Assumptions

Some knowledge of the Windows API would help.

Returns

Opens the respective (Connect To) dialog box or (Disconnect From) dialog box!

Side Effects

not aware of any

API Declarations

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
Public Const RESOURCETYPE_DISK = &H1, RESOURCETYPE_PRINT = 0

Code

Create a Form with 4 command buttons.
Name the first three buttons: 'Command1' (This will create a Control Array)
Label the first button: 'Connect Drive'
Label the second button: 'Disconnect Drive'
Label the third button: 'End Capture'
Label the fourth button: 'Quit'
Double-Click on one the button labelled "Connect Drive" and enter the following:
Private Sub Command1_Click(Index As Integer) <<== You won't need this line
  Dim x As Long
  If Index = 0 Then  'Connect
    x = WNetConnectionDialog(Me.hwnd, RESOURCETYPE_DISK)
  ElseIf Index = 1 Then 'Disconnect
    x = WNetDisconnectDialog(Me.hwnd, RESOURCETYPE_DISK)
  Else
    End
  End If
End Sub <<== You won't need this line either.
Name the fourth button 'printerbutton'. Double-Click it and enter the following:
Private Sub printerbutton_Click()
  Dim x As Long
  x = WNetDisconnectDialog(Me.hwnd, RESOURCETYPE_PRINT)
End Sub
Run the app and click each of the buttons to see what happens!
Hope you find it useful!
If you're interested in trading VB code tips, email me at: kkeller@1stnet.com


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.