⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.frm

📁 很好的教程原代码!
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Main 
   Caption         =   "Form1"
   ClientHeight    =   4035
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5175
   LinkTopic       =   "Form1"
   ScaleHeight     =   4035
   ScaleWidth      =   5175
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "删除映射"
      Height          =   375
      Left            =   960
      TabIndex        =   5
      Top             =   2520
      Width           =   2415
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   1320
      TabIndex        =   4
      Text            =   "Text2"
      Top             =   1080
      Width           =   3495
   End
   Begin VB.CommandButton Command1 
      Caption         =   "映射"
      Height          =   375
      Left            =   960
      TabIndex        =   2
      Top             =   1800
      Width           =   2415
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1320
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   480
      Width           =   3495
   End
   Begin VB.Label Label2 
      Caption         =   "映射盘符:"
      Height          =   255
      Left            =   360
      TabIndex        =   3
      Top             =   1080
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "映射目录:"
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   600
      Width           =   1215
   End
End
Attribute VB_Name = "Main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    Dim NetR As NETRESOURCE
    Dim ErrInfo As Long
    Dim MyPass As String, MyUser As String
    NetR.dwScope = RESOURCE_GLOBALNET
    NetR.dwType = RESOURCETYPE_DISK
    NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
    NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
    NetR.lpLocalName = Text2   ' If undefined, Connect with no device"
    NetR.lpRemoteName = Text1  ' Your valid share
    
    'NetR.lpComment = "Optional Comment"
    'NetR.lpProvider =    ' Leave this undefined
    ' If the UserName and Password arguments are NULL,the user context
    ' for the process provides the default user name.
    ErrInfo = WNetAddConnection2(NetR, MyPass, MyUser, _
        CONNECT_UPDATE_PROFILE)
    If ErrInfo = NO_ERROR Then
        MsgBox "Net Connection Successful!", vbInformation, _
        "Share Connected"
    Else
        MsgBox "ERROR: " & ErrInfo & " - Net Connection Failed!", _
        vbExclamation, "Share not Connected"
    End If
End Sub


Private Sub Command2_Click()
    Dim ErrInfo As Long
    Dim strLocalName As String
    ' You may specify either the lpRemoteName or lpLocalName
    'strLocalName = "\\server\public\"
    strLocalName = Text2.Text
    ErrInfo = WNetCancelConnection2(strLocalName, _
        CONNECT_UPDATE_PROFILE, False)
    If ErrInfo = NO_ERROR Then
       MsgBox "Net Disconnection Successful!", vbInformation, _
       "Share Disconnected"
    Else
       MsgBox "ERROR: " & ErrInfo & " - Net Disconnection Failed!", _
       vbExclamation, "Share not Disconnected"
    End If
End Sub




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -