📄 frmmain.frm
字号:
VERSION 5.00
Begin VB.Form frmMain
Caption = "建立和断开网络映射驱动器"
ClientHeight = 4245
ClientLeft = 3195
ClientTop = 2400
ClientWidth = 6375
LinkTopic = "Form1"
ScaleHeight = 4245
ScaleWidth = 6375
Begin VB.Frame Frame2
Caption = "断开"
Height = 3975
Left = 3240
TabIndex = 2
Top = 120
Width = 3015
Begin VB.TextBox Text1
Height = 285
Index = 4
Left = 120
TabIndex = 12
Text = "Z:"
Top = 600
Width = 2175
End
Begin VB.CommandButton cmdDisconnect
Caption = "断开"
Height = 495
Left = 1680
TabIndex = 3
Top = 3360
Width = 1215
End
Begin VB.Label Label1
Caption = "本地机名称"
Height = 255
Index = 4
Left = 120
TabIndex = 13
Top = 360
Width = 2175
End
End
Begin VB.Frame Frame1
Caption = "连接"
Height = 3975
Left = 120
TabIndex = 0
Top = 120
Width = 3015
Begin VB.TextBox Text1
Height = 285
IMEMode = 3 'DISABLE
Index = 3
Left = 240
PasswordChar = "*"
TabIndex = 10
Text = "0"
Top = 2400
Width = 2535
End
Begin VB.TextBox Text1
Height = 285
Index = 2
Left = 240
TabIndex = 8
Text = "0"
Top = 1800
Width = 2535
End
Begin VB.TextBox Text1
Height = 285
Index = 1
Left = 240
TabIndex = 6
Text = "\\SOLO\Cabs"
Top = 1200
Width = 2535
End
Begin VB.TextBox Text1
Height = 285
Index = 0
Left = 240
TabIndex = 4
Text = "Z:"
Top = 600
Width = 2535
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 495
Left = 1680
TabIndex = 1
Top = 3360
Width = 1215
End
Begin VB.Label Label1
Caption = "密码"
Height = 255
Index = 3
Left = 240
TabIndex = 11
Top = 2160
Width = 2175
End
Begin VB.Label Label1
Caption = "用户名"
Height = 255
Index = 2
Left = 240
TabIndex = 9
Top = 1560
Width = 2175
End
Begin VB.Label Label1
Caption = "远程机名称"
Height = 255
Index = 1
Left = 240
TabIndex = 7
Top = 960
Width = 2175
End
Begin VB.Label Label1
Caption = "本地机名称"
Height = 255
Index = 0
Left = 240
TabIndex = 5
Top = 360
Width = 2175
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type
Const NO_ERROR = 0
Const CONNECT_UPDATE_PROFILE = &H1
Const RESOURCETYPE_DISK = &H1
Const RESOURCETYPE_PRINT = &H2
Const RESOURCETYPE_ANY = &H0
Const RESOURCE_CONNECTED = &H1
Const RESOURCE_REMEMBERED = &H3
Const RESOURCE_GLOBALNET = &H2
Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Const RESOURCEDISPLAYTYPE_SERVER = &H2
Const RESOURCEDISPLAYTYPE_SHARE = &H3
Const RESOURCEUSAGE_CONNECTABLE = &H1
Const RESOURCEUSAGE_CONTAINER = &H2
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _
"WNetAddConnection2A" _
(lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _
"WNetCancelConnection2A" _
(ByVal lpName As String, _
ByVal dwFlags As Long, _
ByVal fForce As Long) As Long
'
'
Private Sub cmdConnect_Click()
Dim NetR As NETRESOURCE
Dim ErrInfo As Long
NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = Text1(0).Text
NetR.lpRemoteName = Text1(1).Text
ErrInfo = WNetAddConnection2(NetR, Text1(3).Text, Text1(2).Text, CONNECT_UPDATE_PROFILE)
If ErrInfo = NO_ERROR Then
MsgBox "Net connection successful!", vbInformation
Else
MsgBox "ERROR: " & Str(ErrInfo) & " - Net connection unsuccessful!", _
vbExclamation
End If
End Sub
Private Sub cmdDisconnect_Click()
Dim ErrInfo As Long
Dim strLocalName As String
strLocalName = Text1(4).Text
ErrInfo = WNetCancelConnection2(strLocalName, CONNECT_UPDATE_PROFILE, False)
If ErrInfo = NO_ERROR Then
MsgBox "Net disconnection successful!", vbInformation
Else
MsgBox "ERROR: " & Str(ErrInfo) & " - Net disconnection unsuccessful!", _
vbExclamation
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -