home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap38 / frmvbnet.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-11  |  4.2 KB  |  142 lines

  1. VERSION 4.00
  2. Begin VB.Form frmVBNetwork 
  3.    Caption         =   "Connecting To Network Resources"
  4.    ClientHeight    =   3600
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1485
  7.    ClientWidth     =   4890
  8.    Height          =   4005
  9.    Left            =   2220
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3600
  12.    ScaleWidth      =   4890
  13.    Top             =   1140
  14.    Width           =   5010
  15.    Begin VB.TextBox txtDrive 
  16.       Height          =   285
  17.       Left            =   2520
  18.       TabIndex        =   1
  19.       Text            =   "txtDrive"
  20.       Top             =   960
  21.       Width           =   1575
  22.    End
  23.    Begin VB.CommandButton cmdDisconnect 
  24.       Caption         =   "&Disconnect"
  25.       Height          =   375
  26.       Left            =   2520
  27.       TabIndex        =   5
  28.       Top             =   3120
  29.       Width           =   1215
  30.    End
  31.    Begin VB.CommandButton cmdConnect 
  32.       Caption         =   "&Connect"
  33.       Height          =   375
  34.       Left            =   1080
  35.       TabIndex        =   4
  36.       Top             =   3120
  37.       Width           =   1215
  38.    End
  39.    Begin VB.DriveListBox Drive1 
  40.       Height          =   315
  41.       Left            =   360
  42.       TabIndex        =   3
  43.       Top             =   2520
  44.       Width           =   4095
  45.    End
  46.    Begin VB.TextBox txtPassWord 
  47.       Height          =   375
  48.       Left            =   360
  49.       TabIndex        =   2
  50.       Text            =   "txtPassWord"
  51.       Top             =   1680
  52.       Width           =   4095
  53.    End
  54.    Begin VB.TextBox txtNetPath 
  55.       Height          =   375
  56.       Left            =   360
  57.       TabIndex        =   0
  58.       Text            =   "txtNetPath"
  59.       Top             =   360
  60.       Width           =   4095
  61.    End
  62.    Begin VB.Label lblDrive 
  63.       Alignment       =   1  'Right Justify
  64.       Caption         =   "Connect Drive Letter:"
  65.       Height          =   255
  66.       Left            =   600
  67.       TabIndex        =   9
  68.       Top             =   960
  69.       Width           =   1695
  70.    End
  71.    Begin VB.Label Label3 
  72.       Alignment       =   2  'Center
  73.       Caption         =   "Current Connections"
  74.       Height          =   255
  75.       Left            =   360
  76.       TabIndex        =   8
  77.       Top             =   2280
  78.       Width           =   4095
  79.    End
  80.    Begin VB.Label Label2 
  81.       Alignment       =   2  'Center
  82.       Caption         =   "PassWord (If Required)"
  83.       Height          =   255
  84.       Left            =   360
  85.       TabIndex        =   7
  86.       Top             =   1440
  87.       Width           =   4095
  88.    End
  89.    Begin VB.Label Label1 
  90.       Alignment       =   2  'Center
  91.       Caption         =   "Path To Network Resource"
  92.       Height          =   255
  93.       Left            =   360
  94.       TabIndex        =   6
  95.       Top             =   120
  96.       Width           =   4095
  97.    End
  98. Attribute VB_Name = "frmVBNetwork"
  99. Attribute VB_Creatable = False
  100. Attribute VB_Exposed = False
  101. Private Sub cmdConnect_Click()
  102. Dim ServerText As String, PassWordText As String
  103. Dim DriveLetter As String, UserName As String
  104. Dim Msg As String
  105. Dim Succeed As Long
  106. Dim nrConnect As NETRESOURCE
  107. nrConnect.lngType = RESOURCETYPE_DISK
  108. nrConnect.strLocalName = txtDrive
  109. nrConnect.strRemoteName = UCase$(txtNetPath)
  110. nrConnect.strProvider = ""
  111. ServerText = UCase$(txtNetPath)
  112. PassWordText = txtPassWord
  113. DriveLetter = txtDrive
  114. 'Succeed = WNetAddConnection(ServerText, PassWordText, DriveLetter)
  115. Succeed = WNetAddConnection2(nrConnect, PassWordText, UserName, CONNECT_UPDATE_PROFILE)
  116. If IsSuccess(Succeed, Msg) = True Then
  117.                                        
  118.     Drive1.Refresh
  119.     MsgBox Msg, , "Visual Basic Unleashed!"
  120.          
  121. End If
  122. End Sub
  123. Private Sub Command1_Click()
  124. End Sub
  125. Private Sub cmdDisconnect_Click()
  126. Dim DriveLetter As String, Msg As String
  127. Dim Succeed As Long
  128.   DriveLetter = Mid$(Drive1.Drive, 1, 2)
  129.   'DriveLetter = txtDrive
  130.   Succeed = WNetCancelConnection(DriveLetter, True)
  131.   If IsSuccess(Succeed, Msg) = True Then
  132.      Drive1.Refresh
  133.   Else
  134.      MsgBox Msg, , "Visual Basic Unleashed!"
  135.   End If
  136. End Sub
  137. Private Sub Form_Load()
  138. txtNetPath = ""
  139. txtDrive = ""
  140. txtPassWord = ""
  141. End Sub
  142.