home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD44253312000.psc / Drivemapper.bas < prev    next >
Encoding:
BASIC Source File  |  2000-03-31  |  2.1 KB  |  74 lines

  1. Attribute VB_Name = "Drivemapper"
  2. Option Explicit
  3.  
  4. Private Const CONNECT_UPDATE_PROFILE = &H1
  5.  
  6. Private Const RESOURCE_CONNECTED As Long = &H1&
  7. Private Const RESOURCE_GLOBALNET As Long = &H2&
  8. Private Const RESOURCETYPE_DISK As Long = &H1&
  9. Private Const RESOURCEDISPLAYTYPE_SHARE& = &H3
  10. Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1&
  11.  
  12. Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
  13.         Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, _
  14.         ByVal lpPassword As String, ByVal lpUserName As String, _
  15.         ByVal dwflags As Long) As Long
  16.  
  17. Private Declare Function WNetCancelConnection2 Lib "mpr.dll" _
  18.         Alias "WNetCancelConnection2A" (ByVal lpName As String, _
  19.         ByVal dwflags As Long, ByVal fForce As Long) As Long
  20.  
  21.  
  22.  
  23. Private Type NETCONNECT
  24.     dwScope As Long
  25.     dwType As Long
  26.     dwDisplayType As Long
  27.     dwUsage As Long
  28.     lpLocalName As String
  29.     lpRemoteName As String
  30.     lpComment As String
  31.     lpProvider As String
  32. End Type
  33.  
  34. Private Declare Function GetSystemMetrics Lib "user32" (ByVal _
  35.         nIndex As Long) As Long
  36.  
  37. Private Const SM_NETWORK = 63
  38.  
  39. Public Function MapDrive(LocalDrive As String, _
  40.             RemoteDrive As String, Optional Username As String, _
  41.             Optional Password As String) As Boolean
  42.  
  43.     'Example:
  44.     'MapDrive "Q:", "\\RemoteMachine\RemoteDirectory", _
  45.      '"MyLoginName", "MyPassword"
  46.  
  47.     Dim NetR As NETCONNECT
  48.  
  49.     NetR.dwScope = RESOURCE_GLOBALNET
  50.     NetR.dwType = RESOURCETYPE_DISK
  51.     NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
  52.     NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
  53.     NetR.lpLocalName = Left$(LocalDrive, 1) & ":"
  54.     NetR.lpRemoteName = RemoteDrive
  55.  
  56.     MapDrive = (WNetAddConnection2(NetR, Username, Password, _
  57.             CONNECT_UPDATE_PROFILE) = 0)
  58.  
  59.  
  60. End Function
  61.  
  62. Public Function UnmapDrive(LocalDrive As String) As Boolean
  63.  
  64.     UnmapDrive = WNetCancelConnection2(Left$(LocalDrive, 1) & ":", _
  65.             CONNECT_UPDATE_PROFILE, False) = 0
  66.  
  67. End Function
  68. Public Function IsNetInstalled() As Boolean
  69.     Dim IsNetworkInstalled
  70.  
  71.     IsNetworkInstalled = GetSystemMetrics(SM_NETWORK)
  72. End Function
  73.  
  74.