当前位置:首页 > 编程学习 > VB获取光驱盘符

VB获取光驱盘符

编程学习2007-04-2954470

VB获取光驱盘符

Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
'GetLogicalDriveStrings-->获取一个字串,其中包含了当前所有逻辑驱动器的根驱动器路径
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
       
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
       
Private Sub Command1_Click()
    Dim rtn As String
    Dim AllDrives As String
    Dim JustOneDrive As String
    AllDrives = Space$(64) '设置缓冲
    rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串
    AllDrives = Left(AllDrives, rtn)
    Do
        rtn = InStr(AllDrives, Chr(0))
        If rtn Then '若有的话
            JustOneDrive = Left(AllDrives, rtn)
            AllDrives = Mid(AllDrives, rtn + 1, Len(AllDrives))
            rtn = GetDriveType(JustOneDrive) '检查驱动器类型
            If rtn = DRIVE_CDROM Then '是CD-ROM
                Label1.Caption = Left(UCase(JustOneDrive), 2) '给label1
                Exit Do
            End If
        End If
    Loop Until AllDrives = "" Or rtn = DRIVE_CDROM
    Command1.Enabled = False
    If Label1.Caption = "" Then Label1.Caption = "没有发现光驱!"
End Sub


扫描二维码推送至手机访问。

版权声明:本文由海阔天空发布,如需转载请注明出处。

本文链接:https://apull.net/html/20070429182.html

标签: 编程技术VB
分享给朋友:

相关文章

VB.NET 用ShellExecuteEx 打开系统文件属性对话框 模块

VB.NET 用ShellExecuteEx 打开系统文件属性对话框 模块

' ' VB.NET 调用系统文件属性对话框模块 ' ' by: Apull ' QQ:374237545 ' http://www.apull.net ' 2007-6-9 ' ' Imports System.Runtime.InteropServices     Mod...

 C++ string类常用函数

C++ string类常用函数

string类的构造函数:string(const char *s);    //用c字符串s初始化 string(int n,char  c);     //用n个字符c初始化此外,string类还支持默认构造函数和复制构造函数,如string s1;string  s2="hello";都是正确的写法。...

计算机蓝屏代码的含义

计算机蓝屏代码的含义

0 0x0000 作业完成。1 0x0001 不正确的函数。2 0x0002 系统找不到指定的档案。3 0x0003 系统找不到指定的路径。4 0x0004 系统无法开启档案。5 0x0005 拒绝存取。6 0x0006 无效的代码。7 0x0007 储存体控制区块已毁。8 0x0008 储存体空间不足,无法处理这个指令。9 0x0009 储存体控制区块地址无效。10 0x000A 环境不正确。11 0x000B 尝试加载一个格式错误的程序。12 0x000C 存取码错误。1...

ASP六大对象介绍

ASP六大对象介绍

Application对象 Application对象是个应用程序级的对象,用来在所有用户间共享信息,并可以在Web应用程序运行期间持久地保持数据。 Application的属性:  方法如下: Application对象没有内置的属性,但是我们可以自行创建其属性。 <% Application("属性名")=值 %>    其实大部分Application变量都 存放在Contents集合中,当你创建一个新的Application变量时,其实...