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

📄 form1.frm

📁 本文件包含200个visual baisc实例
💻 FRM
字号:
VERSION 5.00
Begin VB.Form form1 
   Caption         =   "检测有无映射驱动器"
   ClientHeight    =   3270
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6000
   LinkTopic       =   "Form1"
   ScaleHeight     =   3270
   ScaleWidth      =   6000
   StartUpPosition =   1  '所有者中心
   Begin VB.CommandButton Command2 
      Cancel          =   -1  'True
      Caption         =   "退出"
      Height          =   375
      Left            =   3060
      TabIndex        =   3
      Top             =   2760
      Width           =   1275
   End
   Begin VB.ListBox List1 
      Height          =   2220
      Left            =   120
      TabIndex        =   1
      Top             =   360
      Width           =   5775
   End
   Begin VB.CommandButton Command1 
      Caption         =   "检测"
      Height          =   375
      Left            =   1770
      TabIndex        =   0
      Top             =   2760
      Width           =   1275
   End
   Begin VB.Label Label2 
      Height          =   255
      Left            =   2790
      TabIndex        =   4
      Top             =   90
      Width           =   3135
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "网络映射驱动器列表:"
      Height          =   180
      Left            =   180
      TabIndex        =   2
      Top             =   120
      Width           =   1890
   End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" _
    (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, _
    cbRemoteName As Long) As Long
Private Const NO_ERROR = 0
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_NOT_CONNECTED = 2250&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_CONNECTION_UNAVAIL = 1201&
Private Const ERROR_NO_NETWORK = 1222&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Const MAX_PATH = 260

Private Sub Command1_Click()   '监测网络驱动器
  Dim drv As Integer
  Dim nRet As Long
  Dim lpl As String
  Dim Dbg As String
  Dim lpr As String
  Dim cbr As Long
  List1.Clear      '清空列表
  For drv = Asc("C") To Asc("Z")   '设置驱动器范围
      If Len(Chr(drv)) Then
         lpl = UCase(Left(Chr(drv), 1)) & ":"
         lpr = Space(MAX_PATH)
         cbr = Len(lpr)
         nRet = WNetGetConnection(lpl, lpr, cbr)
         If nRet = ERROR_MORE_DATA Then
            lpr = Space(cbr)
            nRet = WNetGetConnection(lpl, lpr, cbr)
         End If
         If nRet = NO_ERROR Then
            List1.AddItem Chr(drv) & ":  " & Left(lpr, InStr(lpr, vbNullChar) - 1)  '将网络驱动器添加到列表
         End If
      End If
  Next drv
  Label2.Caption = "共有网络驱动器:" & List1.ListCount & "  个"
End Sub

Private Sub Command2_Click()
  End
End Sub



⌨️ 快捷键说明

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