当前位置: 源码素材网 » VB教程 » 详情页

VB 使用API获取计算机中所有的驱动器名称

  •   时间:2019-04-29
  • 概述:Api 驱动器 盘符

VB 使用API获取计算机中所有的驱动器名称

VB 使用API获取计算机中所有的驱动器名称

具体的VB代码分享如下:

VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "使用API获取计算机中所有的驱动器名称"
   ClientHeight    =   1665
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6585
   LinkTopic       =   "Form1"
   ScaleHeight     =   1665
   ScaleWidth      =   6585
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "退出"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4320
      TabIndex        =   3
      Top             =   1200
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "显示驱动器"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2040
      TabIndex        =   2
      Top             =   1200
      Width           =   2055
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   15
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   300
      Left            =   120
      TabIndex        =   1
      Top             =   600
      Width           =   165
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "计算机中所有的驱动器如下:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   18
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   4875
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
'Download by http://www.codesc.net
Attribute VB_Exposed = False
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Command1_Click()
    Dim StrDrive As String   '盘符串(A:\ C:\ D:\...)
    Dim DriveID As String '盘符(如:A:\)
    StrDrive = String(100, Chr$(0))  '初始化盘符串
    Call GetLogicalDriveStrings(100, StrDrive) '返回盘符串
    Dim i As Integer
    Dim str As String
    '返回光盘盘符到数组
    For i = 1 To 100 Step 4 '注意这里是4
        DriveID = Mid(StrDrive, i, 3) '枚举盘符
        If DriveID = Chr$(0) & Chr(0) & Chr(0) Then Exit For '没有盘符,即时退出循环
        str = str & " " & Left(DriveID, 1) & "  盘"
    Next i
    Label2.Caption = str
End Sub
Private Sub Command2_Click()
End
End Sub

    相关声明:

      若“VB 使用API获取计算机中所有的驱动器名称”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。